Skip to content

Commit

Permalink
Merge branch 'master' into update-installment-service
Browse files Browse the repository at this point in the history
  • Loading branch information
mozcan authored Dec 19, 2024
2 parents ed2b408 + 65f2bf9 commit 1574627
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ Apache Maven:
<dependency>
<groupId>io.craftgate</groupId>
<artifactId>craftgate</artifactId>
<version>1.0.60</version>
<version>1.0.61</version>
</dependency>
```
Gradle Groovy DSL
```
implementation 'io.craftgate:craftgate:1.0.60'
implementation 'io.craftgate:craftgate:1.0.61'
```
Gradle Kotlin DSL
```
implementation("io.craftgate:craftgate:1.0.60")
implementation("io.craftgate:craftgate:1.0.61")
```

## Usage
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/craftgate/adapter/BaseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static Map<String, String> createHttpHeaders(Object request, String path
headers.put(API_KEY_HEADER_NAME, options.getApiKey());
headers.put(RANDOM_HEADER_NAME, randomString);
headers.put(AUTH_VERSION_HEADER_NAME, API_VERSION_HEADER_VALUE);
headers.put(CLIENT_VERSION_HEADER_NAME, CLIENT_VERSION_HEADER_VALUE + ":1.0.60");
headers.put(CLIENT_VERSION_HEADER_NAME, CLIENT_VERSION_HEADER_VALUE + ":1.0.61");
headers.put(SIGNATURE_HEADER_NAME, prepareAuthorizationString(request, path, randomString, options));
if (Objects.nonNull(options.getLanguage())) {
headers.put(LANGUAGE_HEADER_NAME, options.getLanguage());
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/craftgate/adapter/PaymentAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ public PaymentTransactionRefundResponse retrievePaymentTransactionRefund(Long id
return HttpClient.get(requestOptions.getBaseUrl() + path, createHeaders(path, requestOptions), PaymentTransactionRefundResponse.class);
}

public PaymentTransactionRefundResponse refundPaymentTransactionMarkAsRefunded(RefundPaymentTransactionMarkAsRefundedRequest refundPaymentTransactionMarkAsRefundedRequest) {
String path = "/payment/v1/refund-transactions/manual";
return HttpClient.post(requestOptions.getBaseUrl() + path, createHeaders(refundPaymentTransactionMarkAsRefundedRequest, path, requestOptions),
refundPaymentTransactionMarkAsRefundedRequest, PaymentTransactionRefundResponse.class);
}

public PaymentRefundResponse refundPayment(RefundPaymentRequest refundPaymentRequest) {
String path = "/payment/v1/refunds";
return HttpClient.post(requestOptions.getBaseUrl() + path, createHeaders(refundPaymentRequest, path, requestOptions),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/craftgate/model/ApmType.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public enum ApmType {
ISPAY,
CHIPPIN,
PAYMOB,
BIZUM,
FUND_TRANSFER,
CASH_ON_DELIVERY
}
1 change: 1 addition & 0 deletions src/main/java/io/craftgate/model/PaymentProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ public enum PaymentProvider {
ISPAY,
CHIPPIN,
PAYMOB,
BIZUM,
OFFLINE,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.craftgate.request;

import io.craftgate.model.RefundDestinationType;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class RefundPaymentTransactionMarkAsRefundedRequest {

private Long paymentTransactionRefundId;
private String conversationId;
private String description;

@Builder.Default
private RefundDestinationType refundDestinationType = RefundDestinationType.PROVIDER;

@Builder.Default
private Boolean chargeFromMe = false;
}
51 changes: 50 additions & 1 deletion src/test/java/io/craftgate/sample/PaymentSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ void init_garanti_pay_payment() {
.paymentGroup(PaymentGroup.LISTING_OR_SUBSCRIPTION)
.items(items)
.installments(installments)
.enabledInstallments(Arrays.asList(2,3))
.enabledInstallments(Arrays.asList(2, 3))
.build();

InitGarantiPayPaymentResponse response = craftgate.payment().initGarantiPayPayment(request);
Expand Down Expand Up @@ -1315,6 +1315,43 @@ void init_chippin_apm_payment() {
assertEquals(ApmAdditionalAction.WAIT_FOR_WEBHOOK, response.getAdditionalAction());
}

@Test
void init_bizum_apm_payment() {
List<PaymentItem> items = new ArrayList<>();

items.add(PaymentItem.builder()
.name("item 1")
.externalId(UUID.randomUUID().toString())
.price(BigDecimal.valueOf(0.6))
.build());

items.add(PaymentItem.builder()
.name("item 2")
.externalId(UUID.randomUUID().toString())
.price(BigDecimal.valueOf(0.4))
.build());

Map<String, String> additionalParams = new HashMap<>();
additionalParams.put("buyerPhoneNumber", "34700000000");

InitApmPaymentRequest request = InitApmPaymentRequest.builder()
.apmType(ApmType.BIZUM)
.price(BigDecimal.ONE)
.paidPrice(BigDecimal.ONE)
.currency(Currency.EUR)
.paymentGroup(PaymentGroup.LISTING_OR_SUBSCRIPTION)
.conversationId("conversationId")
.externalId("externalId")
.additionalParams(additionalParams)
.items(items)
.build();

ApmPaymentInitResponse response = craftgate.payment().initApmPayment(request);
assertNotNull(response.getPaymentId());
assertEquals(PaymentStatus.WAITING, response.getPaymentStatus());
assertEquals(ApmAdditionalAction.WAIT_FOR_WEBHOOK, response.getAdditionalAction());
}


@Test
void init_paymob_apm_payment() {
Expand Down Expand Up @@ -1579,6 +1616,18 @@ void retrieve_payment_transaction_refund() {
assertEquals(RefundStatus.SUCCESS, response.getStatus());
}

@Test
void refund_payment_transaction_mark_as_refunded() {
RefundPaymentTransactionMarkAsRefundedRequest request = RefundPaymentTransactionMarkAsRefundedRequest.builder()
.paymentTransactionRefundId(1L)
.description("marked as refunded")
.build();

PaymentTransactionRefundResponse response = craftgate.payment().refundPaymentTransactionMarkAsRefunded(request);
assertNotNull(response);
assertEquals(RefundStatus.SUCCESS, response.getStatus());
}

@Test
void store_card() {
final StoreCardRequest storeCardRequest = StoreCardRequest.builder()
Expand Down

0 comments on commit 1574627

Please sign in to comment.