Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SecurionPay] Implemented refund/3 #166

Open
wants to merge 1 commit into
base: securion-pay
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/gringotts/gateways/securion_pay.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,33 @@ defmodule Gringotts.Gateways.SecurionPay do
commit([], "charges/#{payment_id}/capture", opts)
end

@doc """
Refunds the `amount` to the customer's account with reference to a prior transfer.

> Refunds are allowed on which kinds of "prior" transactions?

## Note

> The end customer will usually see two bookings/records on his statement. Is
> that true for SecurionPay?
> Is there a limited time window within which a void can be perfomed?

## Example

> A barebones example using the bindings you've suggested in the `moduledoc`.
"""
@spec refund(Money.t(), String.t(), keyword) :: {:ok | :error, Response}
def refund(amount, payment_id, opts) do
{currency, value, _, _} = Money.to_integer_exp(amount)
url = "charges/#{payment_id}/refund"

[amount: value]
|>commit(url, opts)


end


##########################################################################
# PRIVATE METHODS #
##########################################################################
Expand Down
20 changes: 20 additions & 0 deletions test/integration/gateways/securion_pay_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ defmodule Gringotts.Integration.Gateways.SecurionPayTest do
brand: "VISA"
}


@opts [
config: [secret_key: "pr_test_tXHm9qV9qV9bjIRHcQr9PLPa"],
customer_id: "cust_NxPh6PUq9KWUW8tZKkUnV2Nt"
Expand All @@ -40,6 +41,7 @@ defmodule Gringotts.Integration.Gateways.SecurionPayTest do
@bad_opts [config: [secret_key: "pr_test_tXHm9qV9qV9bjIRHcQr9PLPa"]]

@card_id "card_wVuO1a5BGM12UV10FwpkK9YW"
@charge_id "char_kA8MOArQQUMtYki0XHybr9fb"
@bad_charge_id "char_wVuO1a5BGM12UV10FwpkK9YW"

describe "[authorize]" do
Expand Down Expand Up @@ -99,4 +101,22 @@ defmodule Gringotts.Integration.Gateways.SecurionPayTest do
end
end
end

describe "[refund]" do
test "with_authorized_payment_id" do
use_cassette "securion_pay/valid_refund" do
assert {:ok, response} = Gateway.refund(@amount, @charge_id, @opts)
assert response.success == true
assert response.status_code == 200
end
end

test "with_invalid_payment_id" do
use_cassette "securion_pay/invalid_refund" do
assert {:error, response} = Gateway.refund(@amount, @bad_charge_id, @opts)
assert response.success == false
refute response.status_code == 200
end
end
end
end