forked from Flutterwave/Ruby-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Iphytech/iphie/ukAndEuAccount
add pay with uk and eu account
- Loading branch information
Showing
3 changed files
with
111 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
lib/flutterwave_sdk/flutterwave_objects/uk_and_eu_account.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require_relative "base/base.rb" | ||
require 'json' | ||
|
||
class UkPayment < Base | ||
def initiate_charge(data) | ||
base_url = flutterwave_object.base_url | ||
|
||
# only update the payload with the transaction reference if it isn't already added to the payload | ||
if !data.key?("tx_ref") | ||
data.merge!({"tx_ref" => Util.transaction_reference_generator}) | ||
end | ||
# check the currency to determine the type and the required parameters | ||
currency = data["currency"] | ||
if currency == "GBP" | ||
required_parameters = [ "amount", "email", "tx_ref", "currency", "is_token_io"] | ||
type = "account-ach-uk" | ||
elsif currency == "EUR" | ||
required_parameters = [ "amount", "email", "tx_ref", "currency", "is_token_io"] | ||
type = "account-ach-uk" | ||
else | ||
return "pass a valid currency" | ||
end | ||
|
||
check_passed_parameters(required_parameters, data) | ||
type = type | ||
payload = data.to_json | ||
|
||
response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}?type=#{type}", payload) | ||
return response | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require 'dotenv' | ||
require 'spec_helper' | ||
require "flutterwave_sdk/flutterwave_objects/uk_and_eu_account" | ||
|
||
Dotenv.load | ||
|
||
test_public_key = ENV['TEST_PUBLIC_KEY'] | ||
test_secret_key = ENV['TEST_SECRET_KEY'] | ||
test_encryption_key = ENV['TEST_ENCRYPTION_KEY'] | ||
|
||
payload = { | ||
"amount" => "100", | ||
"email" => "[email protected]", | ||
"tx_ref" => "MC-#{Time.now.to_i}", | ||
"currency" => "GBP", | ||
"is_token_io" => 1 | ||
} | ||
|
||
incomplete_payload = { | ||
"amount" => "100", | ||
"email" => "[email protected]", | ||
"tx_ref" => "MC-#{Time.now.to_i}", | ||
"currency" => "GBP", | ||
} | ||
|
||
invalid_currency_payload = { | ||
"amount" => "100", | ||
"email" => "[email protected]", | ||
"tx_ref" => "MC-#{Time.now.to_i}", | ||
"currency" => "NGN", | ||
"is_token_io" => 1 | ||
} | ||
|
||
RSpec.describe UkPayment do | ||
flutterwave = Flutterwave.new(test_public_key, test_secret_key, test_encryption_key) | ||
payment = UkPayment.new(flutterwave) | ||
payment_charge = payment.initiate_charge(payload) | ||
|
||
|
||
context "when a merchant tries to charge a customers via mobile money" do | ||
it "should return a ach payment object" do | ||
expect(payment.nil?).to eq(false) | ||
end | ||
|
||
it 'should raise Error if the ach payload is incomplete' do | ||
begin | ||
incomplete_payment_response = payment.initiate_charge(incomplete_payload) | ||
rescue => e | ||
expect(e.instance_of? IncompleteParameterError).to eq true | ||
end | ||
end | ||
|
||
it 'should successfully initate payment and return authorization mode for the charge' do | ||
payload_response = payment_charge | ||
expect(payload_response["data"]["status"]).to eq("pending") | ||
expect(payload_response["message"]).to eq("Charge initiated") | ||
expect(payload_response["meta"]["authorization"]["mode"]).to eq("redirect") | ||
end | ||
|
||
it 'should successfully return processor response ' do | ||
payload_response = payment_charge | ||
expect(payload_response["data"]["processor_response"]).to eq("Transaction is pending authentication") | ||
end | ||
|
||
it 'should successfully return the auth model' do | ||
payload_response = payment_charge | ||
expect(payload_response["data"]["auth_model"]).to eq("TOKEN") | ||
end | ||
|
||
end | ||
end |