Skip to content

Commit

Permalink
CybersourceREST - Refund | Credit
Browse files Browse the repository at this point in the history
Description
-------------------------
This integration support the following payment operations:
- Refund
- Credit

Unit test
-------------------------
Finished in 29.776044 seconds.
5452 tests, 77126 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Remote test
-------------------------
183.10 tests/s, 2590.20 assertions/s

Rubocop
-------------------------
760 files inspected, no offenses detected
  • Loading branch information
Luis committed Feb 10, 2023
1 parent 72ba52f commit 86556a2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
34 changes: 33 additions & 1 deletion lib/active_merchant/billing/gateways/cyber_source_rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ def authorize(money, payment, options = {})
commit('/pts/v2/payments/', post)
end

def refund(money, options = {})
post = build_refund_request(money, options)

yield post if block_given?

commit("/pts/v2/payments/#{options[:order_id]}/refunds", post)
end

def credit(money, payment, options = {})
post = build_credit_request(money, payment, options)

yield post if block_given?

commit('/pts/v2/credits', post)
end

def supports_scrubbing?
true
end
Expand All @@ -74,6 +90,22 @@ def build_auth_request(amount, payment, options)
end.compact
end

def build_refund_request(amount, options)
{ clientReferenceInformation: {}, orderInformation: {} }.tap do |post|
add_code(post, options)
add_amount(post, amount)
end.compact
end

def build_credit_request(amount, payment, options)
{ clientReferenceInformation: {}, paymentInformation: {}, orderInformation: {} }.tap do |post|
add_code(post, options)
add_credit_card(post, payment)
add_amount(post, amount)
add_address(post, payment, options[:billing_address], options, :billTo)
end.compact
end

def add_code(post, options)
return unless options[:order_id].present?

Expand Down Expand Up @@ -161,7 +193,7 @@ def commit(action, post)
end

def success_from(response)
response['status'] == 'AUTHORIZED'
%w(AUTHORIZED PENDING).include?(response['status'])
end

def message_from(response)
Expand Down
21 changes: 21 additions & 0 deletions test/remote/gateways/remote_cyber_source_rest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ def test_successful_purchase
assert_nil response.params['_links']['capture']
end

def test_successful_refund
purchase = @gateway.purchase(@amount, @visa_card, @options)
response = @gateway.refund(@amount, { order_id: purchase.authorization })

assert_success response
assert response.test?
assert_equal 'PENDING', response.message
assert response.params['id'].present?
assert_nil response.params['_links']['capture']
end

def test_successful_credit
response = @gateway.credit(@amount, @visa_card, @options)

assert_success response
assert response.test?
assert_equal 'PENDING', response.message
assert response.params['id'].present?
assert_nil response.params['_links']['capture']
end

def test_transcript_scrubbing
transcript = capture_transcript(@gateway) do
@gateway.authorize(@amount, @visa_card, @options)
Expand Down

0 comments on commit 86556a2

Please sign in to comment.