app/models/workarea/payment/refund/afterpay.rb in workarea-afterpay-2.0.2 vs app/models/workarea/payment/refund/afterpay.rb in workarea-afterpay-2.1.0
- old
+ new
@@ -4,14 +4,12 @@
class Afterpay
include OperationImplementation
include CreditCardOperation
def complete!
- request_id = SecureRandom.uuid
+ response = refund
- response = gateway.refund(afterpay_order_id, transaction.amount, request_id)
-
if response.success?
transaction.response = ActiveMerchant::Billing::Response.new(
true,
I18n.t(
'workarea.afterpay.refund',
@@ -31,11 +29,10 @@
def cancel!
# No op - no cancel functionality available.
end
private
-
def gateway
currency = transaction.amount.currency.iso_code
location = Workarea::Afterpay.config[:currency_country_map][currency.to_sym]
location = location.to_sym.downcase
@@ -43,9 +40,24 @@
Workarea::Afterpay.gateway(location)
end
def afterpay_order_id
transaction.reference.response.params["id"]
+ end
+
+ def refund
+ request_id = SecureRandom.uuid
+ refund_response = response(request_id)
+
+ if Workarea::Afterpay::RETRY_ERROR_STATUSES.include? refund_response.status
+ return response(request_id)
+ end
+
+ refund_response
+ end
+
+ def response(request_id)
+ gateway.refund(afterpay_order_id, transaction.amount, request_id)
end
end
end
end
end