use of com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.CardPaymentMethodSpecificInput in project connect-sdk-java by Ingenico-ePayments.
the class CreatePaymentExample method example.
@SuppressWarnings("unused")
public void example() throws URISyntaxException, IOException {
Client client = getClient();
try {
Card card = new Card();
card.setCardNumber("4567350000427977");
card.setCardholderName("Wile E. Coyote");
card.setCvv("123");
card.setExpiryDate("1220");
CardPaymentMethodSpecificInput cardPaymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
cardPaymentMethodSpecificInput.setCard(card);
cardPaymentMethodSpecificInput.setPaymentProductId(1);
cardPaymentMethodSpecificInput.setSkipAuthentication(false);
AmountOfMoney amountOfMoney = new AmountOfMoney();
amountOfMoney.setAmount(2980L);
amountOfMoney.setCurrencyCode("EUR");
Address billingAddress = new Address();
billingAddress.setAdditionalInfo("b");
billingAddress.setCity("Monument Valley");
billingAddress.setCountryCode("US");
billingAddress.setHouseNumber("13");
billingAddress.setState("Utah");
billingAddress.setStreet("Desertroad");
billingAddress.setZip("84536");
CompanyInformation companyInformation = new CompanyInformation();
companyInformation.setName("Acme Labs");
ContactDetails contactDetails = new ContactDetails();
contactDetails.setEmailAddress("wile.e.coyote@acmelabs.com");
contactDetails.setEmailMessageType("html");
contactDetails.setFaxNumber("+1234567891");
contactDetails.setPhoneNumber("+1234567890");
PersonalName name = new PersonalName();
name.setFirstName("Wile");
name.setSurname("Coyote");
name.setSurnamePrefix("E.");
name.setTitle("Mr.");
PersonalInformation personalInformation = new PersonalInformation();
personalInformation.setDateOfBirth("19490917");
personalInformation.setGender("M");
personalInformation.setName(name);
PersonalName shippingName = new PersonalName();
shippingName.setFirstName("Road");
shippingName.setSurname("Runner");
shippingName.setTitle("Miss");
AddressPersonal shippingAddress = new AddressPersonal();
shippingAddress.setAdditionalInfo("Suite II");
shippingAddress.setCity("Monument Valley");
shippingAddress.setCountryCode("US");
shippingAddress.setHouseNumber("1");
shippingAddress.setName(shippingName);
shippingAddress.setState("Utah");
shippingAddress.setStreet("Desertroad");
shippingAddress.setZip("84536");
Customer customer = new Customer();
customer.setBillingAddress(billingAddress);
customer.setCompanyInformation(companyInformation);
customer.setContactDetails(contactDetails);
customer.setLocale("en_US");
customer.setMerchantCustomerId("1234");
customer.setPersonalInformation(personalInformation);
customer.setShippingAddress(shippingAddress);
customer.setVatNumber("1234AB5678CD");
OrderInvoiceData invoiceData = new OrderInvoiceData();
invoiceData.setInvoiceDate("20140306191500");
invoiceData.setInvoiceNumber("000000123");
OrderReferences references = new OrderReferences();
references.setDescriptor("Fast and Furry-ous");
references.setInvoiceData(invoiceData);
references.setMerchantOrderId(123456L);
references.setMerchantReference("AcmeOrder0001");
List<LineItem> items = new ArrayList<LineItem>();
AmountOfMoney item1AmountOfMoney = new AmountOfMoney();
item1AmountOfMoney.setAmount(2500L);
item1AmountOfMoney.setCurrencyCode("EUR");
LineItemInvoiceData item1InvoiceData = new LineItemInvoiceData();
item1InvoiceData.setDescription("ACME Super Outfit");
item1InvoiceData.setNrOfItems("1");
item1InvoiceData.setPricePerItem(2500L);
LineItem item1 = new LineItem();
item1.setAmountOfMoney(item1AmountOfMoney);
item1.setInvoiceData(item1InvoiceData);
items.add(item1);
AmountOfMoney item2AmountOfMoney = new AmountOfMoney();
item2AmountOfMoney.setAmount(480L);
item2AmountOfMoney.setCurrencyCode("EUR");
LineItemInvoiceData item2InvoiceData = new LineItemInvoiceData();
item2InvoiceData.setDescription("Aspirin");
item2InvoiceData.setNrOfItems("12");
item2InvoiceData.setPricePerItem(40L);
LineItem item2 = new LineItem();
item2.setAmountOfMoney(item2AmountOfMoney);
item2.setInvoiceData(item2InvoiceData);
items.add(item2);
ShoppingCart shoppingCart = new ShoppingCart();
shoppingCart.setItems(items);
Order order = new Order();
order.setAmountOfMoney(amountOfMoney);
order.setCustomer(customer);
order.setReferences(references);
order.setShoppingCart(shoppingCart);
CreatePaymentRequest body = new CreatePaymentRequest();
body.setCardPaymentMethodSpecificInput(cardPaymentMethodSpecificInput);
body.setOrder(order);
try {
CreatePaymentResponse response = client.merchant("merchantId").payments().create(body);
} catch (DeclinedPaymentException e) {
handleDeclinedPayment(e.getCreatePaymentResult());
} catch (ApiException e) {
handleApiErrors(e.getErrors());
}
} finally {
client.close();
}
}
use of com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.CardPaymentMethodSpecificInput in project connect-sdk-java by Ingenico-ePayments.
the class DefaultConnectionLoggerTest method testCreatePayment.
@Test
public void testCreatePayment() throws Exception {
// POST with a success (201) response
serverBootstrap.registerHandler("/v1/1234/payments", requestHandler);
HttpHost host = start();
Client client = createClient(host);
TestLogger logger = new TestLogger();
client.enableLogging(logger);
setupRequestHandler(setCreatedJsonResponse("createPayment.json", "http://localhost/v1/1234/payments/000000123410000595980000100001"));
try {
AmountOfMoney amountOfMoney = new AmountOfMoney();
amountOfMoney.setCurrencyCode("CAD");
amountOfMoney.setAmount(2345L);
Address billingAddress = new Address();
billingAddress.setCountryCode("CA");
Customer customer = new Customer();
customer.setBillingAddress(billingAddress);
Order order = new Order();
order.setAmountOfMoney(amountOfMoney);
order.setCustomer(customer);
Card card = new Card();
card.setCvv("123");
card.setCardNumber("1234567890123456");
card.setExpiryDate("1220");
CardPaymentMethodSpecificInput paymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
paymentMethodSpecificInput.setPaymentProductId(1);
paymentMethodSpecificInput.setCard(card);
CreatePaymentRequest request = new CreatePaymentRequest();
request.setOrder(order);
request.setCardPaymentMethodSpecificInput(paymentMethodSpecificInput);
CreatePaymentResponse response = client.merchant("1234").payments().create(request);
Assert.assertNotNull(response);
Assert.assertNotNull(response.getPayment());
Assert.assertNotNull(response.getPayment().getId());
} finally {
client.close();
}
Assert.assertEquals(2, logger.entries.size());
TestLoggerEntry requestEntry = logger.entries.get(0);
Assert.assertNotNull(requestEntry.message);
Assert.assertNull(requestEntry.thrown);
TestLoggerEntry responseEntry = logger.entries.get(1);
Assert.assertNotNull(responseEntry.message);
Assert.assertNull(responseEntry.thrown);
assertRequestAndResponse(requestEntry.message, responseEntry.message, "createPayment");
}
use of com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.CardPaymentMethodSpecificInput in project connect-sdk-java by Ingenico-ePayments.
the class DefaultConnectionLoggerTest method testCreatePaymentInvalidCardNumber.
@Test
public void testCreatePaymentInvalidCardNumber() throws Exception {
// an exception is thrown after logging the response
serverBootstrap.registerHandler("/v1/1234/payments", requestHandler);
HttpHost host = start();
Client client = createClient(host);
TestLogger logger = new TestLogger();
client.enableLogging(logger);
setupRequestHandler(setJsonResponse("createPayment.failure.invalidCardNumber.json", 400));
try {
AmountOfMoney amountOfMoney = new AmountOfMoney();
amountOfMoney.setCurrencyCode("CAD");
amountOfMoney.setAmount(2345L);
Address billingAddress = new Address();
billingAddress.setCountryCode("CA");
Customer customer = new Customer();
customer.setBillingAddress(billingAddress);
Order order = new Order();
order.setAmountOfMoney(amountOfMoney);
order.setCustomer(customer);
Card card = new Card();
card.setCvv("123");
card.setCardNumber("1234567890123456");
card.setExpiryDate("1220");
CardPaymentMethodSpecificInput paymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
paymentMethodSpecificInput.setPaymentProductId(1);
paymentMethodSpecificInput.setCard(card);
CreatePaymentRequest request = new CreatePaymentRequest();
request.setOrder(order);
request.setCardPaymentMethodSpecificInput(paymentMethodSpecificInput);
client.merchant("1234").payments().create(request);
Assert.fail("expected ValidationException");
} catch (ValidationException e) {
// expected
} finally {
client.close();
}
Assert.assertEquals(2, logger.entries.size());
TestLoggerEntry requestEntry = logger.entries.get(0);
Assert.assertNotNull(requestEntry.message);
Assert.assertNull(requestEntry.thrown);
TestLoggerEntry responseEntry = logger.entries.get(1);
Assert.assertNotNull(responseEntry.message);
Assert.assertNull(responseEntry.thrown);
assertRequestAndResponse(requestEntry.message, responseEntry.message, "createPayment.failure.invalidCardNumber");
}
use of com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.CardPaymentMethodSpecificInput in project connect-sdk-java by Ingenico-ePayments.
the class DefaultConnectionLoggerTest method testCreatePaymentRejected.
@Test
public void testCreatePaymentRejected() throws Exception {
// an exception is thrown after logging the response
serverBootstrap.registerHandler("/v1/1234/payments", requestHandler);
HttpHost host = start();
Client client = createClient(host);
TestLogger logger = new TestLogger();
client.enableLogging(logger);
setupRequestHandler(setJsonResponse("createPayment.failure.rejected.json", 402));
try {
AmountOfMoney amountOfMoney = new AmountOfMoney();
amountOfMoney.setCurrencyCode("CAD");
amountOfMoney.setAmount(2345L);
Address billingAddress = new Address();
billingAddress.setCountryCode("CA");
Customer customer = new Customer();
customer.setBillingAddress(billingAddress);
Order order = new Order();
order.setAmountOfMoney(amountOfMoney);
order.setCustomer(customer);
Card card = new Card();
card.setCvv("123");
card.setCardNumber("1234567890123452");
card.setExpiryDate("1220");
CardPaymentMethodSpecificInput paymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
paymentMethodSpecificInput.setPaymentProductId(1);
paymentMethodSpecificInput.setCard(card);
CreatePaymentRequest request = new CreatePaymentRequest();
request.setOrder(order);
request.setCardPaymentMethodSpecificInput(paymentMethodSpecificInput);
client.merchant("1234").payments().create(request);
Assert.fail("expected DeclinedPaymentException");
} catch (DeclinedPaymentException e) {
// expected
Assert.assertNotNull(e.getCreatePaymentResult());
Assert.assertNotNull(e.getCreatePaymentResult().getPayment());
Assert.assertNotNull(e.getCreatePaymentResult().getPayment().getId());
} finally {
client.close();
}
Assert.assertEquals(2, logger.entries.size());
TestLoggerEntry requestEntry = logger.entries.get(0);
Assert.assertNotNull(requestEntry.message);
Assert.assertNull(requestEntry.thrown);
TestLoggerEntry responseEntry = logger.entries.get(1);
Assert.assertNotNull(responseEntry.message);
Assert.assertNull(responseEntry.thrown);
assertRequestAndResponse(requestEntry.message, responseEntry.message, "createPayment.failure.rejected");
}
use of com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.CardPaymentMethodSpecificInput in project connect-sdk-java by Ingenico-ePayments.
the class PaymentsClientTest method createRequest.
private CreatePaymentRequest createRequest() {
CreatePaymentRequest body = new CreatePaymentRequest();
Order order = new Order();
AmountOfMoney amountOfMoney = new AmountOfMoney();
amountOfMoney.setAmount(2345L);
amountOfMoney.setCurrencyCode("CAD");
order.setAmountOfMoney(amountOfMoney);
Customer customer = new Customer();
Address billingAddress = new Address();
billingAddress.setCountryCode("CA");
customer.setBillingAddress(billingAddress);
order.setCustomer(customer);
CardPaymentMethodSpecificInput cardPaymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
cardPaymentMethodSpecificInput.setPaymentProductId(1);
Card card = new Card();
card.setCvv("123");
card.setCardNumber("4567350000427977");
card.setExpiryDate("1220");
cardPaymentMethodSpecificInput.setCard(card);
body.setCardPaymentMethodSpecificInput(cardPaymentMethodSpecificInput);
return body;
}
Aggregations