Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/com/shift4/enums/ChargeFlowActionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.fasterxml.jackson.annotation.JsonValue;

public enum ChargeFlowActionType {

APP_REDIRECT("app_redirect"),
QR_CODE("qr_code"),
MOBILE_APP_CONFIRMATION("mobile_app_confirmation"),
REDIRECT("redirect"),
WAIT("wait"),
NONE("none"),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/shift4/enums/PaymentMethodType.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum PaymentMethodType {
PAYU("payu"),
PERLAS("perlas"),
SKRILL("skrill"),
SWISH("swish"),
TRUSTLY("trustly"),
UNIONPAY("unionpay"),
VERKKOPANKKI("verkkopankki"),
Expand Down
97 changes: 84 additions & 13 deletions src/main/java/com/shift4/request/PaymentMethodRequest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.shift4.request;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.*;
import com.shift4.enums.PaymentMethodType;
import com.shift4.response.Customer;
import com.shift4.response.FraudCheckData;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -17,10 +13,12 @@ public class PaymentMethodRequest {
private String customerId;
private PaymentMethodType type;
private BillingRequest billing;
private FraudCheckData fraudCheckData;
private FraudCheckDataRequest fraudCheckData;
private ApplePay applePay;
private ThreeDSecure threeDSecure;
private GooglePay googlePay;
private Swish swish;
private Blik blik;
private String source;
private Map<String, String> metadata;
private String merchantAccountId;
Expand Down Expand Up @@ -55,7 +53,7 @@ public BillingRequest getBilling() {
return billing;
}

public FraudCheckData getFraudCheckData() {
public FraudCheckDataRequest getFraudCheckData() {
return fraudCheckData;
}

Expand All @@ -71,6 +69,14 @@ public GooglePay getGooglePay() {
return googlePay;
}

public Swish getSwish() {
return swish;
}

public Blik getBlik() {
return blik;
}

public String getSource() {
return source;
}
Expand Down Expand Up @@ -107,7 +113,7 @@ public PaymentMethodRequest billing(BillingRequest billing) {
return this;
}

public PaymentMethodRequest fraudCheckData(FraudCheckData fraudCheckData) {
public PaymentMethodRequest fraudCheckData(FraudCheckDataRequest fraudCheckData) {
this.fraudCheckData = fraudCheckData;
return this;
}
Expand All @@ -127,6 +133,17 @@ public PaymentMethodRequest googlePay(GooglePay googlePay) {
return this;
}

public PaymentMethodRequest swish(Swish swish) {
this.swish = swish;
return this;
}


public PaymentMethodRequest blik(Blik blik) {
this.blik = blik;
return this;
}

public PaymentMethodRequest source(String source) {
this.source = source;
return this;
Expand Down Expand Up @@ -184,11 +201,69 @@ public ApplePay set(String name, Object value) {
}
}

public static class Swish {
private SwishLinkMethod linkMethod;

@JsonIgnore
private final Map<String, Object> other = new HashMap<>();

public Swish(SwishLinkMethod linkMethod) {
this.linkMethod = linkMethod;
}

public SwishLinkMethod getLinkMethod() {
return linkMethod;
}

@JsonAnyGetter
private Map<String, Object> getOtherMap() {
return other;
}

@JsonAnySetter
public Swish set(String name, Object value) {
other.put(name, value);
return this;
}

public enum SwishLinkMethod {
@JsonProperty("app_redirect") APP_REDIRECT,
@JsonProperty("phone_number") PHONE_NUMBER,
@JsonProperty("qr_code") QR_CODE
}
}

public static class Blik {
private String code;

@JsonIgnore
private final Map<String, Object> other = new HashMap<>();

public Blik code(String code) {
this.code = code;
return this;
}

public String getCode() {
return code;
}

@JsonAnyGetter
private Map<String, Object> getOtherMap() {
return other;
}

@JsonAnySetter
public Blik set(String name, Object value) {
other.put(name, value);
return this;
}
}

public static class ThreeDSecure {
private String currency;
private Integer amount;


public ThreeDSecure(String currency, Integer amount) {
this.currency = currency;
this.amount = amount;
Expand Down Expand Up @@ -255,9 +330,5 @@ public GooglePay set(String name, Object value) {
other.put(name, value);
return this;
}

}



}
1 change: 0 additions & 1 deletion src/main/java/com/shift4/response/PaymentMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ private void set(String name, Object value) {
}
}


public static class GooglePay {
private String cardBrand;
private String cardType;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/shift4/CustomerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void shouldCreateCustomer() {
// then
assertThat(created.isDeleted()).isFalse();
assertThat(created.getId()).isNotBlank();
assertThat(created.getEmail()).isEqualTo(request.getEmail());
assertThat(created.getEmail()).isEqualToIgnoringCase(request.getEmail());
assertThat(created.getDescription()).isEqualTo(request.getDescription());
assertThat(created.getMetadata()).isEqualTo(request.getMetadata());
}
Expand Down
79 changes: 72 additions & 7 deletions src/test/java/com/shift4/PaymentMethodIT.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.shift4;

import com.shift4.enums.PaymentMethodType;
import com.shift4.request.AddressRequest;
import com.shift4.request.BillingRequest;
import com.shift4.request.FraudCheckDataRequest;
import com.shift4.request.PaymentMethodRequest;
import com.shift4.response.PaymentMethod;
import org.junit.jupiter.api.Test;
Expand All @@ -10,7 +13,7 @@
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;

public class PaymentMethodIT extends AbstractShift4GatewayTest{
public class PaymentMethodIT extends AbstractShift4GatewayTest {

@Test
void shouldCreatePaymentMethodFromToken() {
Expand All @@ -37,7 +40,7 @@ void shouldCreatePaymentMethodFromToken() {
void shouldCreateGooglePayPaymentMethod() {
// when
PaymentMethod paymentMethod = gateway.createPaymentMethod(new PaymentMethodRequest(PaymentMethodType.GOOGLE_PAY)
.googlePay(new PaymentMethodRequest.GooglePay("PAN_ONLY")));
.googlePay(new PaymentMethodRequest.GooglePay("PAN_ONLY")));

// then
assertThat(paymentMethod).isNotNull();
Expand All @@ -53,17 +56,79 @@ void shouldCreateGooglePayPaymentMethod() {
assertThat(paymentMethod.getFlow().getNextAction()).isNotNull();
}

@Test
void shouldCreateSwishPaymentMethod() {
// when
PaymentMethod paymentMethod = gateway.createPaymentMethod(new PaymentMethodRequest(PaymentMethodType.SWISH)
.billing(new BillingRequest().address(new AddressRequest().country("SE")).name("John Doe"))
.swish(new PaymentMethodRequest.Swish(PaymentMethodRequest.Swish.SwishLinkMethod.QR_CODE)));

// then
assertThat(paymentMethod).isNotNull();
assertThat(paymentMethod.getId()).isNotNull();
assertThat(paymentMethod.getType()).isEqualTo(PaymentMethodType.SWISH);

assertThat(paymentMethod.getFlow()).isNotNull();
assertThat(paymentMethod.getFlow().getNextAction()).isNotNull();
}

@Test
void shouldCreateBlikPaymentMethod() {
// when
PaymentMethod paymentMethod = gateway.createPaymentMethod(new PaymentMethodRequest(PaymentMethodType.BLIK)
.billing(new BillingRequest().address(new AddressRequest().country("PL")).name("John Doe")));

// then
assertThat(paymentMethod).isNotNull();
assertThat(paymentMethod.getId()).isNotNull();
assertThat(paymentMethod.getType()).isEqualTo(PaymentMethodType.BLIK);

assertThat(paymentMethod.getFlow()).isNotNull();
assertThat(paymentMethod.getFlow().getNextAction()).isNotNull();
}

@Test
void shouldCreateBlikWithCodePaymentMethod() {
// when
PaymentMethod paymentMethod = gateway.createPaymentMethod(new PaymentMethodRequest(PaymentMethodType.BLIK)
.billing(new BillingRequest().address(new AddressRequest().country("PL")).name("John Doe"))
.fraudCheckData(new FraudCheckDataRequest().userAgent("").ipAddress("127.0.0.1"))
.blik(new PaymentMethodRequest.Blik().code("123456")));

// then
assertThat(paymentMethod).isNotNull();
assertThat(paymentMethod.getId()).isNotNull();
assertThat(paymentMethod.getType()).isEqualTo(PaymentMethodType.BLIK);

assertThat(paymentMethod.getFlow()).isNotNull();
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
PaymentMethod source = gateway.createPaymentMethod(new PaymentMethodRequest(PaymentMethodType.GOOGLE_PAY)
.googlePay(new PaymentMethodRequest.GooglePay("CRYPTOGRAM_3DS")));
.googlePay(new PaymentMethodRequest.GooglePay("CRYPTOGRAM_3DS")));
PaymentMethod paymentMethod = gateway.createPaymentMethod(new PaymentMethodRequest(PaymentMethodType.THREE_D_SECURE)
.source(source.getId())
.source(source.getId())
.googlePay(new PaymentMethodRequest.GooglePay("CRYPTOGRAM_3DS"))
.threeDSecure(new PaymentMethodRequest.ThreeDSecure()
.currency("USD")
.amount(60))
.threeDSecure(new PaymentMethodRequest.ThreeDSecure()
.currency("USD")
.amount(60))
);

// then
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/com/shift4/PayoutsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.shift4.request.ChargeRequest;
import com.shift4.request.CreatedFilter;
import com.shift4.request.PayoutListRequest;
import com.shift4.response.Charge;
import com.shift4.response.ListResponse;
import com.shift4.response.Payout;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.util.Optional;
Expand All @@ -20,7 +20,7 @@ public class PayoutsTest extends AbstractShift4GatewayTest {
void shouldCreatePayout() {
// given
ChargeRequest request = charge().card(successCard()).currency("EUR");
Charge charge = gateway.createCharge(request);
gateway.createCharge(request);

// when
Payout payout = gateway.createPayout();
Expand All @@ -31,21 +31,21 @@ void shouldCreatePayout() {
}

@Test
@Disabled
void shouldListPayouts() {
// given
ChargeRequest request = charge().card(successCard()).currency("EUR");
Charge charge = gateway.createCharge(request);
gateway.createCharge(request);

// when
Payout payout = gateway.createPayout();
ListResponse<Payout> payouts = gateway.listPayouts(new PayoutListRequest().created(new CreatedFilter().gte(payout.getCreated())));
ListResponse<Payout> payouts = gateway.listPayouts(new PayoutListRequest().limit(100));

// then
Optional<Payout> foundPayout = payouts.getList().stream().filter(
p -> p.getId().equals(payout.getId())
).findFirst();
assertThat(foundPayout.isPresent());
Optional<Payout> foundPayout = payouts.getList().stream()
.filter(caondidatePayout -> caondidatePayout.getId().equals(payout.getId()))
.findFirst();
assertThat(foundPayout).isPresent();
assertThat(foundPayout.get().getCurrency()).isEqualTo("EUR");

}
}