Skip to content

Commit

Permalink
Merge pull request #11 from Affirm/PSE-1206
Browse files Browse the repository at this point in the history
migrating /void and /refund to /transactions
  • Loading branch information
ninersontherize authored Apr 14, 2022
2 parents 65d252f + 683c8c4 commit e722dd9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions affirmpaymentcore/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import com.affirm.payment.AffirmPaymentConstants;

import java.math.BigDecimal;

public class AffirmRefundPaymentRequestServiceBuilder extends AffirmPaymentRequestServiceBuilder<AffirmRefundPaymentRequestServiceBuilder> {

public AffirmRefundPaymentRequestServiceBuilder setRefundAmount(final BigDecimal amount)
public AffirmRefundPaymentRequestServiceBuilder setRefundAmount(final int amount)
{
affirmPaymentServiceRequest.addParam(AffirmPaymentConstants.REFUND.AMOUNT, amount);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,26 @@ 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.");
}

AffirmPaymentServiceRequest request = new AffirmRefundPaymentRequestServiceBuilder()
.setOrder(order)
.setTransactionObjectId(authorisationEntry.getProperties().get(ID))
.setTransactionType(PaymentTransactionType.REFUND_STANDALONE)
.setRefundAmount(amount)
.setRefundAmount(int_amount)
.build();

AffirmPaymentServiceResult paymentServiceResult = affirmPaymentServiceExecutor.execute(request);
Expand Down

0 comments on commit e722dd9

Please sign in to comment.