From 683c8c4d6ce350e6079d526287d957c5ae9eaa3b Mon Sep 17 00:00:00 2001 From: Ryan McNicol Date: Thu, 14 Apr 2022 09:09:59 -0700 Subject: [PATCH] migrating /void and /refund to /transactions --- affirmpaymentcore/project.properties | 4 ++-- ...AffirmRefundPaymentRequestServiceBuilder.java | 4 +--- .../impl/DefaultAffirmPaymentService.java | 16 ++++++++++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/affirmpaymentcore/project.properties b/affirmpaymentcore/project.properties index d1292ce..2d6c1d9 100755 --- a/affirmpaymentcore/project.properties +++ b/affirmpaymentcore/project.properties @@ -34,6 +34,6 @@ affirm.extension.version=Affirm_1.0 affirm.merchant.name=Hybris - Affirm plugin affirm.authorisation.endpoint=BASE_URL/api/v1/transactions affirm.capture.endpoint=BASE_URL/api/v1/transactions/TRANSACTION_OBJECT_ID/capture -affirm.refund.endpoint=BASE_URL/api/v2/charges/TRANSACTION_OBJECT_ID/refund -affirm.void.endpoint=BASE_URL/api/v2/charges/TRANSACTION_OBJECT_ID/void +affirm.refund.endpoint=BASE_URL/api/v1/transactions/TRANSACTION_OBJECT_ID/refund +affirm.void.endpoint=BASE_URL/api/v1/transactions/TRANSACTION_OBJECT_ID/void affirm.update.endpoint=BASE_URL/api/v1/transactions/TRANSACTION_OBJECT_ID \ No newline at end of file diff --git a/affirmpaymentcore/src/com/affirm/payment/service/executor/request/builder/AffirmRefundPaymentRequestServiceBuilder.java b/affirmpaymentcore/src/com/affirm/payment/service/executor/request/builder/AffirmRefundPaymentRequestServiceBuilder.java index 6652c27..03c8401 100644 --- a/affirmpaymentcore/src/com/affirm/payment/service/executor/request/builder/AffirmRefundPaymentRequestServiceBuilder.java +++ b/affirmpaymentcore/src/com/affirm/payment/service/executor/request/builder/AffirmRefundPaymentRequestServiceBuilder.java @@ -2,11 +2,9 @@ import com.affirm.payment.AffirmPaymentConstants; -import java.math.BigDecimal; - public class AffirmRefundPaymentRequestServiceBuilder extends AffirmPaymentRequestServiceBuilder { - public AffirmRefundPaymentRequestServiceBuilder setRefundAmount(final BigDecimal amount) + public AffirmRefundPaymentRequestServiceBuilder setRefundAmount(final int amount) { affirmPaymentServiceRequest.addParam(AffirmPaymentConstants.REFUND.AMOUNT, amount); return this; diff --git a/affirmpaymentcore/src/com/affirm/payment/service/impl/DefaultAffirmPaymentService.java b/affirmpaymentcore/src/com/affirm/payment/service/impl/DefaultAffirmPaymentService.java index a6cc35b..2435482 100644 --- a/affirmpaymentcore/src/com/affirm/payment/service/impl/DefaultAffirmPaymentService.java +++ b/affirmpaymentcore/src/com/affirm/payment/service/impl/DefaultAffirmPaymentService.java @@ -123,14 +123,18 @@ public class DefaultAffirmPaymentService implements AffirmPaymentService{ @Override public boolean refundOrder(OrderModel order, BigDecimal amount) { AffirmPaymentTransactionEntryModel authorisationEntry = affirmPaymentTransactionStrategy.getAcceptedTransaction(order, PaymentTransactionType.AUTHORIZATION); AffirmPaymentTransactionEntryModel captureEntry = affirmPaymentTransactionStrategy.getAcceptedTransaction(order, PaymentTransactionType.CAPTURE); - if(authorisationEntry == null || captureEntry == null){ + int int_amount = amount.intValue(); + + if(authorisationEntry == null || captureEntry == null) { throw new AffirmPaymentException(AffirmPaymentConstants.REASON_CODE.INVALID_DATA, "Refund is not possible as authorisation and / or capture entry is not exist."); } - if(amount != null) { - amount = amount.multiply(BigDecimal.valueOf(100)); - } - if(!affirmPaymentCoreService.isRefundPossible(order, amount)){ + if(amount != null) { + amount = amount.multiply(BigDecimal.valueOf(100)); + int_amount = amount.intValue(); + } + + if(!affirmPaymentCoreService.isRefundPossible(order, amount)){ throw new AffirmPaymentException(AffirmPaymentConstants.REASON_CODE.INVALID_DATA, "It is not possible to refund more that the order total."); } @@ -138,7 +142,7 @@ public class DefaultAffirmPaymentService implements AffirmPaymentService{ .setOrder(order) .setTransactionObjectId(authorisationEntry.getProperties().get(ID)) .setTransactionType(PaymentTransactionType.REFUND_STANDALONE) - .setRefundAmount(amount) + .setRefundAmount(int_amount) .build(); AffirmPaymentServiceResult paymentServiceResult = affirmPaymentServiceExecutor.execute(request);