diff --git a/README.md b/README.md
index 43dce71..0dc3068 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ To do this you will need to add this configuration to your `pom.xml`:
com.shift4
shift4-java
- 3.1.0
+ 3.2.0
```
diff --git a/build.gradle b/build.gradle
index 83f41eb..32bf52d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,7 +6,7 @@ plugins {
}
group = 'com.shift4'
-version = '3.1.0'
+version = '3.2.0'
archivesBaseName = 'shift4-java'
def stagingForReleases = 'staging-deploy/releases'
diff --git a/src/main/java/com/shift4/request/CustomerRequest.java b/src/main/java/com/shift4/request/CustomerRequest.java
index 62e37ee..0ca3eb2 100644
--- a/src/main/java/com/shift4/request/CustomerRequest.java
+++ b/src/main/java/com/shift4/request/CustomerRequest.java
@@ -18,6 +18,7 @@ public class CustomerRequest {
private CardRequest card;
private PaymentMethodRequest paymentMethod;
private Map metadata;
+ private BillingRequest billing;
@JsonIgnore
private final Map other = new HashMap<>();
@@ -83,6 +84,11 @@ public CustomerRequest metadata(Map metadata) {
return this;
}
+ public CustomerRequest billing(BillingRequest billing) {
+ this.billing = billing;
+ return this;
+ }
+
@JsonAnyGetter
private Map getOtherMap() {
return other;
diff --git a/src/main/java/com/shift4/request/CustomerUpdateRequest.java b/src/main/java/com/shift4/request/CustomerUpdateRequest.java
index 8665360..14d0436 100644
--- a/src/main/java/com/shift4/request/CustomerUpdateRequest.java
+++ b/src/main/java/com/shift4/request/CustomerUpdateRequest.java
@@ -24,6 +24,8 @@ public class CustomerUpdateRequest {
private CardRequest card;
private Map metadata;
+ private BillingRequest billing;
+
@JsonIgnore
private final Map other = new HashMap<>();
@@ -109,6 +111,11 @@ public CustomerUpdateRequest metadata(Map metadata) {
return this;
}
+ public CustomerUpdateRequest billing(BillingRequest billing) {
+ this.billing = billing;
+ return this;
+ }
+
@JsonAnyGetter
private Map getOtherMap() {
return other;
diff --git a/src/main/java/com/shift4/response/Customer.java b/src/main/java/com/shift4/response/Customer.java
index b1317e8..7435d07 100644
--- a/src/main/java/com/shift4/response/Customer.java
+++ b/src/main/java/com/shift4/response/Customer.java
@@ -21,6 +21,8 @@ public class Customer {
private List cards;
private Map metadata;
+ private Billing billing;
+
@JsonIgnore
private final Map other = new HashMap<>();
@@ -74,6 +76,10 @@ public Map getMetadata() {
return metadata;
}
+ public Billing getBilling() {
+ return billing;
+ }
+
public String get(String name) {
return Shift4Utils.toStringNullSafe(other.get(name));
}
diff --git a/src/test/java/com/shift4/CustomerTest.java b/src/test/java/com/shift4/CustomerTest.java
index 23a0fbd..85a76ed 100644
--- a/src/test/java/com/shift4/CustomerTest.java
+++ b/src/test/java/com/shift4/CustomerTest.java
@@ -1,16 +1,17 @@
package com.shift4;
-import com.shift4.request.CustomerListRequest;
-import com.shift4.request.CustomerRequest;
-import com.shift4.request.CustomerUpdateRequest;
+import com.shift4.request.*;
import com.shift4.response.Customer;
import com.shift4.response.DeleteResponse;
import com.shift4.response.ListResponse;
import com.shift4.testdata.Emails;
+import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Test;
import static com.shift4.testdata.Customers.customer;
import static java.util.Collections.singletonMap;
+import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
+import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
import static org.assertj.core.api.Assertions.assertThat;
class CustomerTest extends AbstractShift4GatewayTest {
@@ -29,6 +30,7 @@ void shouldCreateCustomer() {
assertThat(created.getEmail()).isEqualToIgnoringCase(request.getEmail());
assertThat(created.getDescription()).isEqualTo(request.getDescription());
assertThat(created.getMetadata()).isEqualTo(request.getMetadata());
+ assertThat(created.getBilling()).isNull();
}
@Test
@@ -94,4 +96,119 @@ void shouldListCustomers() {
.extracting(Customer::getId)
.containsExactly(customer3.getId(), customer2.getId(), customer1.getId());
}
+
+ @Test
+ void shouldCreateAndRetrieveCustomerWithBillingAddress() {
+ //given
+ BillingRequest billingRequest = new BillingRequest()
+ .name(randomAlphabetic(10))
+ .email(Emails.email())
+ .vat(randomAlphabetic(10))
+ .phone(randomNumeric(9))
+ .address(new AddressRequest()
+ .line1(randomAlphabetic(10))
+ .line2(randomAlphabetic(10))
+ .state(randomAlphabetic(10))
+ .zip(randomNumeric(5))
+ .city(randomAlphabetic(10))
+ .country("SE"));
+
+ // when
+ Customer customer = gateway.createCustomer(new CustomerRequest()
+ .email(Emails.email())
+ .billing(billingRequest));
+
+ // then
+ assertThat(customer.getBilling().getEmail()).isEqualTo(billingRequest.getEmail());
+ assertThat(customer.getBilling().getName()).isEqualTo(billingRequest.getName());
+ assertThat(customer.getBilling().getVat()).isEqualTo(billingRequest.getVat());
+ assertThat(customer.getBilling().getPhone()).isEqualTo(billingRequest.getPhone());
+ assertThat(customer.getBilling().getAddress().getLine1()).isEqualTo(billingRequest.getAddress().getLine1());
+ assertThat(customer.getBilling().getAddress().getLine2()).isEqualTo(billingRequest.getAddress().getLine2());
+ assertThat(customer.getBilling().getAddress().getState()).isEqualTo(billingRequest.getAddress().getState());
+ assertThat(customer.getBilling().getAddress().getZip()).isEqualTo(billingRequest.getAddress().getZip());
+ assertThat(customer.getBilling().getAddress().getCity()).isEqualTo(billingRequest.getAddress().getCity());
+ assertThat(customer.getBilling().getAddress().getCountry()).isEqualTo(billingRequest.getAddress().getCountry());
+
+ // when
+ Customer retrieved = gateway.retrieveCustomer(customer.getId());
+
+ // then
+ assertThat(retrieved.getBilling().getEmail()).isEqualTo(billingRequest.getEmail());
+ assertThat(retrieved.getBilling().getName()).isEqualTo(billingRequest.getName());
+ assertThat(retrieved.getBilling().getVat()).isEqualTo(billingRequest.getVat());
+ assertThat(retrieved.getBilling().getPhone()).isEqualTo(billingRequest.getPhone());
+ assertThat(retrieved.getBilling().getAddress().getLine1()).isEqualTo(billingRequest.getAddress().getLine1());
+ assertThat(retrieved.getBilling().getAddress().getLine2()).isEqualTo(billingRequest.getAddress().getLine2());
+ assertThat(retrieved.getBilling().getAddress().getState()).isEqualTo(billingRequest.getAddress().getState());
+ assertThat(retrieved.getBilling().getAddress().getZip()).isEqualTo(billingRequest.getAddress().getZip());
+ assertThat(retrieved.getBilling().getAddress().getCity()).isEqualTo(billingRequest.getAddress().getCity());
+ assertThat(retrieved.getBilling().getAddress().getCountry()).isEqualTo(billingRequest.getAddress().getCountry());
+ }
+
+ @Test
+ void shouldUpdateBillingAddress() {
+ //given
+ BillingRequest billingRequest = new BillingRequest()
+ .name(randomAlphabetic(10))
+ .email(Emails.email())
+ .vat(randomAlphabetic(10))
+ .phone(randomNumeric(9))
+ .address(new AddressRequest()
+ .line1(randomAlphabetic(10))
+ .line2(randomAlphabetic(10))
+ .state(randomAlphabetic(10))
+ .zip(randomNumeric(5))
+ .city(randomAlphabetic(10))
+ .country("SE"));
+
+ Customer customer = gateway.createCustomer(new CustomerRequest()
+ .email(Emails.email())
+ .billing(billingRequest));
+
+ BillingRequest updatedBillingRequest = new BillingRequest()
+ .name(randomAlphabetic(10))
+ .email(Emails.email())
+ .vat(randomAlphabetic(10))
+ .phone(randomNumeric(9))
+ .address(new AddressRequest()
+ .line1(randomAlphabetic(10))
+ .line2(randomAlphabetic(10))
+ .state(randomAlphabetic(10))
+ .zip(randomNumeric(5))
+ .city(randomAlphabetic(10))
+ .country("SE"));
+
+ //when
+ Customer updated = gateway.updateCustomer(new CustomerUpdateRequest()
+ .customer(customer)
+ .billing(updatedBillingRequest));
+
+ //then
+ assertThat(updated.getBilling().getEmail()).isEqualTo(updatedBillingRequest.getEmail());
+ assertThat(updated.getBilling().getName()).isEqualTo(updatedBillingRequest.getName());
+ assertThat(updated.getBilling().getVat()).isEqualTo(updatedBillingRequest.getVat());
+ assertThat(updated.getBilling().getPhone()).isEqualTo(updatedBillingRequest.getPhone());
+ assertThat(updated.getBilling().getAddress().getLine1()).isEqualTo(updatedBillingRequest.getAddress().getLine1());
+ assertThat(updated.getBilling().getAddress().getLine2()).isEqualTo(updatedBillingRequest.getAddress().getLine2());
+ assertThat(updated.getBilling().getAddress().getState()).isEqualTo(updatedBillingRequest.getAddress().getState());
+ assertThat(updated.getBilling().getAddress().getZip()).isEqualTo(updatedBillingRequest.getAddress().getZip());
+ assertThat(updated.getBilling().getAddress().getCity()).isEqualTo(updatedBillingRequest.getAddress().getCity());
+ assertThat(updated.getBilling().getAddress().getCountry()).isEqualTo(updatedBillingRequest.getAddress().getCountry());
+
+ // when
+ Customer retrieved = gateway.retrieveCustomer(customer.getId());
+
+ // then
+ assertThat(retrieved.getBilling().getEmail()).isEqualTo(updatedBillingRequest.getEmail());
+ assertThat(retrieved.getBilling().getName()).isEqualTo(updatedBillingRequest.getName());
+ assertThat(retrieved.getBilling().getVat()).isEqualTo(updatedBillingRequest.getVat());
+ assertThat(retrieved.getBilling().getPhone()).isEqualTo(updatedBillingRequest.getPhone());
+ assertThat(retrieved.getBilling().getAddress().getLine1()).isEqualTo(updatedBillingRequest.getAddress().getLine1());
+ assertThat(retrieved.getBilling().getAddress().getLine2()).isEqualTo(updatedBillingRequest.getAddress().getLine2());
+ assertThat(retrieved.getBilling().getAddress().getState()).isEqualTo(updatedBillingRequest.getAddress().getState());
+ assertThat(retrieved.getBilling().getAddress().getZip()).isEqualTo(updatedBillingRequest.getAddress().getZip());
+ assertThat(retrieved.getBilling().getAddress().getCity()).isEqualTo(updatedBillingRequest.getAddress().getCity());
+ assertThat(retrieved.getBilling().getAddress().getCountry()).isEqualTo(updatedBillingRequest.getAddress().getCountry());
+ }
}
\ No newline at end of file
diff --git a/src/test/java/com/shift4/PaymentMethodIT.java b/src/test/java/com/shift4/PaymentMethodIT.java
index 3a1a47d..033750e 100644
--- a/src/test/java/com/shift4/PaymentMethodIT.java
+++ b/src/test/java/com/shift4/PaymentMethodIT.java
@@ -104,20 +104,6 @@ void shouldCreateBlikWithCodePaymentMethod() {
assertThat(paymentMethod.getFlow().getNextAction()).isNotNull();
}
- @Test
- void shouldCreateKlarnaDebitRiskPaymentMethod() {
- // when
- PaymentMethod paymentMethod = gateway.createPaymentMethod(new PaymentMethodRequest(PaymentMethodType.KLARNA_DEBIT_RISK)
- .billing(new BillingRequest().address(new AddressRequest().country("SE")).name("John Doe")));
-
- // then
- assertThat(paymentMethod).isNotNull();
- assertThat(paymentMethod.getId()).isNotNull();
- assertThat(paymentMethod.getType()).isEqualTo(PaymentMethodType.KLARNA_DEBIT_RISK);
- assertThat(paymentMethod.getFlow()).isNotNull();
- assertThat(paymentMethod.getFlow().getNextAction()).isNotNull();
- }
-
@Test
void shouldCreateGooglePayWithThreeDSecurePaymentMethod() {
// when