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

Skip to content

Commit bc91b6d

Browse files
committed
Add chargeType into charge request and charge response
1 parent 3757b4a commit bc91b6d

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.shift4.enums;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonValue;
5+
6+
public enum ChargeType {
7+
FIRST_RECURRING("first_recurring"),
8+
SUBSEQUENT_RECURRING("subsequent_recurring"),
9+
MERCHANT_INITIATED("merchant_initiated"),
10+
CUSTOMER_INITIATED("customer_initiated"),
11+
12+
/**
13+
* Used when received value can't be mapped to this enumeration.
14+
*/
15+
UNRECOGNIZED("unrecognized"),
16+
;
17+
18+
private final String value;
19+
20+
ChargeType(String value) {
21+
this.value = value;
22+
}
23+
24+
@JsonCreator
25+
public static ChargeType fromValue(String value) {
26+
if (value == null) {
27+
return null;
28+
}
29+
for (ChargeType type : values()) {
30+
if (type.value.equalsIgnoreCase(value)) {
31+
return type;
32+
}
33+
}
34+
35+
return UNRECOGNIZED;
36+
}
37+
38+
@JsonValue
39+
public String getValue() {
40+
return value;
41+
}
42+
}

src/main/java/com/shift4/request/ChargeRequest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.annotation.JsonIgnore;
66
import com.fasterxml.jackson.annotation.JsonInclude;
77
import com.fasterxml.jackson.annotation.JsonInclude.Include;
8+
import com.shift4.enums.ChargeType;
89
import com.shift4.response.Customer;
910

1011
import java.util.HashMap;
@@ -20,6 +21,7 @@ public class ChargeRequest {
2021
private CardRequest card;
2122
private PaymentMethodRequest paymentMethod;
2223
private ChargeFlowRequest flow;
24+
private ChargeType type;
2325
private Boolean captured;
2426
private ShippingRequest shipping;
2527
private BillingRequest billing;
@@ -65,7 +67,11 @@ public ChargeFlowRequest getFlow() {
6567
return flow;
6668
}
6769

68-
public Boolean getCaptured() {
70+
public ChargeType getType() {
71+
return type;
72+
}
73+
74+
public Boolean getCaptured() {
6975
return captured;
7076
}
7177

@@ -128,7 +134,12 @@ public ChargeRequest flow(ChargeFlowRequest flow) {
128134
return this;
129135
}
130136

131-
public ChargeRequest captured(Boolean captured) {
137+
public ChargeRequest type(ChargeType type) {
138+
this.type = type;
139+
return this;
140+
}
141+
142+
public ChargeRequest captured(Boolean captured) {
132143
this.captured = captured;
133144
return this;
134145
}

src/main/java/com/shift4/response/Charge.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonAnySetter;
44
import com.fasterxml.jackson.annotation.JsonIgnore;
55
import com.shift4.enums.ChargeStatus;
6+
import com.shift4.enums.ChargeType;
67
import com.shift4.enums.ErrorCode;
78
import com.shift4.util.Shift4Utils;
89

@@ -20,7 +21,8 @@ public class Charge {
2021
private String currency;
2122
private String description;
2223
private ChargeStatus status;
23-
private Card card;
24+
private ChargeType type;
25+
private Card card;
2426
private PaymentMethod paymentMethod;
2527
private ChargeFlow flow;
2628
private String customerId;
@@ -80,7 +82,11 @@ public ChargeStatus getStatus() {
8082
return status;
8183
}
8284

83-
public Card getCard() {
85+
public ChargeType getType() {
86+
return type;
87+
}
88+
89+
public Card getCard() {
8490
return card;
8591
}
8692

src/test/java/com/shift4/ChargesTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.databind.SerializationFeature;
44
import com.shift4.enums.ChargeStatus;
5+
import com.shift4.enums.ChargeType;
56
import com.shift4.enums.ErrorType;
67
import com.shift4.exception.Shift4Exception;
78
import com.shift4.request.ChargeListRequest;
@@ -141,4 +142,14 @@ void shouldCreateChargeUsingExplicitMerchant() {
141142
assertThat(retrievedCharge.getCurrency()).isEqualTo(request.getCurrency());
142143
assertThat(retrievedCharge.getFailureCode()).isNull();
143144
}
145+
146+
@Test
147+
void shouldSendChargeType() {
148+
// given
149+
ChargeRequest request = charge().card(successCard()).type(ChargeType.CUSTOMER_INITIATED);
150+
// when
151+
Charge charge = gateway.createCharge(request);
152+
// then
153+
assertThat(charge.getType()).isEqualTo(ChargeType.CUSTOMER_INITIATED);
154+
}
144155
}

0 commit comments

Comments
 (0)