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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To do this you will need to add this configuration to your `pom.xml`:
<dependency>
<groupId>com.shift4</groupId>
<artifactId>shift4-java</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = 'com.shift4'
version = '3.3.0'
version = '3.4.0'
archivesBaseName = 'shift4-java'

def stagingForReleases = 'staging-deploy/releases'
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/com/shift4/enums/ChargeType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.shift4.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum ChargeType {
FIRST_RECURRING("first_recurring"),
SUBSEQUENT_RECURRING("subsequent_recurring"),
MERCHANT_INITIATED("merchant_initiated"),
CUSTOMER_INITIATED("customer_initiated"),

/**
* Used when received value can't be mapped to this enumeration.
*/
UNRECOGNIZED("unrecognized"),
;

private final String value;

ChargeType(String value) {
this.value = value;
}

@JsonCreator
public static ChargeType fromValue(String value) {
if (value == null) {
return null;
}
for (ChargeType type : values()) {
if (type.value.equalsIgnoreCase(value)) {
return type;
}
}

return UNRECOGNIZED;
}

@JsonValue
public String getValue() {
return value;
}
}
15 changes: 13 additions & 2 deletions src/main/java/com/shift4/request/ChargeRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.shift4.enums.ChargeType;
import com.shift4.response.Customer;

import java.util.HashMap;
Expand All @@ -20,6 +21,7 @@ public class ChargeRequest {
private CardRequest card;
private PaymentMethodRequest paymentMethod;
private ChargeFlowRequest flow;
private ChargeType type;
private Boolean captured;
private ShippingRequest shipping;
private BillingRequest billing;
Expand Down Expand Up @@ -65,7 +67,11 @@ public ChargeFlowRequest getFlow() {
return flow;
}

public Boolean getCaptured() {
public ChargeType getType() {
return type;
}

public Boolean getCaptured() {
return captured;
}

Expand Down Expand Up @@ -128,7 +134,12 @@ public ChargeRequest flow(ChargeFlowRequest flow) {
return this;
}

public ChargeRequest captured(Boolean captured) {
public ChargeRequest type(ChargeType type) {
this.type = type;
return this;
}

public ChargeRequest captured(Boolean captured) {
this.captured = captured;
return this;
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/shift4/response/Charge.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.shift4.enums.ChargeStatus;
import com.shift4.enums.ChargeType;
import com.shift4.enums.ErrorCode;
import com.shift4.util.Shift4Utils;

Expand All @@ -20,7 +21,8 @@ public class Charge {
private String currency;
private String description;
private ChargeStatus status;
private Card card;
private ChargeType type;
private Card card;
private PaymentMethod paymentMethod;
private ChargeFlow flow;
private String customerId;
Expand Down Expand Up @@ -80,7 +82,11 @@ public ChargeStatus getStatus() {
return status;
}

public Card getCard() {
public ChargeType getType() {
return type;
}

public Card getCard() {
return card;
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/java/com/shift4/ChargesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.SerializationFeature;
import com.shift4.enums.ChargeStatus;
import com.shift4.enums.ChargeType;
import com.shift4.enums.ErrorType;
import com.shift4.exception.Shift4Exception;
import com.shift4.request.ChargeListRequest;
Expand Down Expand Up @@ -141,4 +142,14 @@ void shouldCreateChargeUsingExplicitMerchant() {
assertThat(retrievedCharge.getCurrency()).isEqualTo(request.getCurrency());
assertThat(retrievedCharge.getFailureCode()).isNull();
}

@Test
void shouldSendChargeType() {
// given
ChargeRequest request = charge().card(successCard()).type(ChargeType.CUSTOMER_INITIATED);
// when
Charge charge = gateway.createCharge(request);
// then
assertThat(charge.getType()).isEqualTo(ChargeType.CUSTOMER_INITIATED);
}
}