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

Add pay with Uk and EU Bank Account #8

Open
wants to merge 16 commits into
base: dev
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
/pkg/
/spec/reports/
/tmp/
Gemfile.lock
/Gemfile.lock

.env
/sample_code
sample_code/
sample_code
.DS_Store


# rspec failure tracking
.rspec_status
Expand All @@ -37,3 +41,7 @@ bills_test.rb
preauth_test.rb
rspec_results.html
flutterwave_sdk-0.1.0.gem

.DS_Store
lib/.DS_Store
lib/flutterwave_sdk/.DS_Store
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PATH
remote: .
specs:
flutterwave_sdk (0.1.1)
httparty (~> 0.16.3)
httparty (>= 0.16.3)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -35,11 +35,11 @@ PLATFORMS
ruby

DEPENDENCIES
bundler (~> 2.1.4)
dotenv (~> 2.8.1)
bundler (>= 2.4.19)
dotenv (>= 2.8.1)
flutterwave_sdk!
rake (~> 12.0)
rspec (~> 3.0)

BUNDLED WITH
2.1.4
2.4.19
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.1.1 | 2023-08-30
Updated old dependencies

### Added
- [UPDATE] Dependencies

## [0.1.1] - 2023-07-20
### Added
- Test suite for mobile money TZS transactions.
Expand Down
6 changes: 3 additions & 3 deletions flutterwave_sdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ spec.date = '2020-05-10'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 2.1.4"
spec.add_development_dependency "bundler", ">= 2.4.19"
#add dotenv
spec.add_development_dependency "dotenv", "~> 2.8.1"
spec.add_development_dependency "dotenv", ">= 2.8.1"

# Dependencies
spec.required_ruby_version = ">= 2.5.3"
spec.add_runtime_dependency 'httparty', '~> 0.16.3'
spec.add_runtime_dependency 'httparty', '>= 0.16.3'
end
21 changes: 13 additions & 8 deletions lib/flutterwave_sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative "flutterwave_sdk/flutterwave_objects/base/base"
require_relative "flutterwave_sdk/flutterwave_modules/util"
require_relative "flutterwave_sdk/flutterwave_objects/card"
require_relative "flutterwave_sdk/flutterwave_objects/uk_and_eu_account"
require_relative "flutterwave_sdk/flutterwave_objects/mobile_money"
require_relative "flutterwave_sdk/flutterwave_objects/account_payment"
require_relative "flutterwave_sdk/flutterwave_objects/bank_transfer"
Expand All @@ -23,6 +24,10 @@
require_relative "flutterwave_sdk/flutterwave_objects/virtual_account_number"
require_relative "flutterwave_sdk/flutterwave_objects/bills"
require_relative "flutterwave_sdk/flutterwave_objects/preauthorise"
require_relative "flutterwave_sdk/flutterwave_objects/enaira"
require_relative "flutterwave_sdk/flutterwave_objects/apple_payment"
require_relative "flutterwave_sdk/flutterwave_objects/fawry_payment"
require_relative "flutterwave_sdk/flutterwave_objects/google_payment"
require_relative "flutterwave_sdk/error"

class Flutterwave
Expand Down Expand Up @@ -52,7 +57,7 @@ def base_url
# check if we set our public , secret and encryption keys to the environment variable
if (public_key.nil?)
@public_key = ENV['FLUTTERWAVE_PUBLIC_KEY']
else
else
@public_key = public_key
end

Expand All @@ -77,7 +82,7 @@ def base_url
unless @public_key[0..7] == 'FLWPUBK-' || @public_key[0..11] == 'FLWPUBK_TEST'
raise FlutterwaveBadKeyError, "Invalid public key #{@public_key}"
end

# raise this error if no secret key is passed
unless !@secret_key.nil?
raise FlutterwaveBadKeyError, "No secret key supplied and couldn't find any in environment variables. Make sure to set secret key as an environment variable FLUTTERWAVE_SECRET_KEY"
Expand All @@ -94,11 +99,11 @@ def base_url
end

#tracking activities
def flutterwave_tracking
def flutterwave_tracking
endpoint = "https://kgelfdz7mf.execute-api.us-east-1.amazonaws.com/staging/sendevent"
public_key = @public_key


payload = {
"PBFPubKey" => public_key,
"language" => "Ruby",
Expand All @@ -107,17 +112,17 @@ def flutterwave_tracking
"message" => "test is done"
}
data = payload.to_json

response = HTTParty.post(endpoint, {
body: data,
headers: {
'Content-Type' => 'application/json'
}
})

unless (response.code == 200 || response.code == 201)
raise RaveServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
end
end
return response
end

Expand Down
28 changes: 28 additions & 0 deletions lib/flutterwave_sdk/flutterwave_objects/apple_payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_relative "base/base.rb"
require 'json'

class ApplePayment < 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
required_parameters = [ "amount", "email", "tx_ref", "currency"]

check_passed_parameters(required_parameters, data)
type = "applepay"
payload = data.to_json

response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}?type=#{type}", payload)
return response
end

def verify_charge(id)
base_url = flutterwave_object.base_url

response = get_request("#{base_url}/transactions/#{id}/verify")
return response
end
end
28 changes: 28 additions & 0 deletions lib/flutterwave_sdk/flutterwave_objects/enaira.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_relative "base/base.rb"
require 'json'

class ENairaPayment < 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
required_parameters = [ "amount", "email", "tx_ref", "currency"]

check_passed_parameters(required_parameters, data)
type = "enaira"
payload = data.to_json

response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}?type=#{type}", payload)
return response
end

def verify_charge(id)
base_url = flutterwave_object.base_url

response = get_request("#{base_url}/transactions/#{id}/verify")
return response
end
end
28 changes: 28 additions & 0 deletions lib/flutterwave_sdk/flutterwave_objects/fawry_payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_relative "base/base.rb"
require 'json'

class FawryPayment < 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
required_parameters = [ "amount", "email", "tx_ref", "currency"]

check_passed_parameters(required_parameters, data)
type = "fawry_pay"
payload = data.to_json

response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}?type=#{type}", payload)
return response
end

def verify_charge(id)
base_url = flutterwave_object.base_url

response = get_request("#{base_url}/transactions/#{id}/verify")
return response
end
end
28 changes: 28 additions & 0 deletions lib/flutterwave_sdk/flutterwave_objects/google_payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_relative "base/base.rb"
require 'json'

class GooglePayment < 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
required_parameters = [ "amount", "email", "tx_ref", "currency"]

check_passed_parameters(required_parameters, data)
type = "googlepay"
payload = data.to_json

response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}?type=#{type}", payload)
return response
end

def verify_charge(id)
base_url = flutterwave_object.base_url

response = get_request("#{base_url}/transactions/#{id}/verify")
return response
end
end
38 changes: 38 additions & 0 deletions lib/flutterwave_sdk/flutterwave_objects/uk_and_eu_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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

def verify_charge(id)
base_url = flutterwave_object.base_url

response = get_request("#{base_url}/transactions/#{id}/verify")
return response
end
end
2 changes: 1 addition & 1 deletion lib/flutterwave_sdk/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module FlutterwaveSdk
VERSION = "0.1.1"
VERSION = "1.1.1"
end
83 changes: 83 additions & 0 deletions spec/flutterwave_apple_payment_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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 = {
"tx_ref"=> "MC-" + Date.today.to_s,
"amount"=>"10",
"currency"=>"USD",
"email"=> "[email protected]",
"fullname"=> "Yolande Aglaé Colbert",
"narration"=>"Test payment",
"redirect_url"=>"http=>//localhost=>9000/dump",
"client_ip"=>"192.168.0.1",
"device_fingerprint"=>"gdgdhdh738bhshsjs",
"billing_zip"=>"15101",
"billing_city"=>"allison park",
"billing_address"=>"3563 Huntertown Rd",
"billing_state"=>"Pennsylvania",
"billing_country"=>"US",
"phone_number"=>"09012345678",
"meta"=>{
"metaname"=>"testmeta",
"metavalue"=>"testvalue"
}
}

incomplete_payload = {
"amount" => "10",
"email" => "[email protected]",
"tx_ref" => "MC-#{Time.now.to_i}",
}

invalid_currency_payload = {
"amount" => "100",
"email" => "[email protected]",
"tx_ref" => "MC-#{Time.now.to_i}",
"currency" => "NGN",
}

RSpec.describe ApplePayment do
flutterwave = Flutterwave.new(test_public_key, test_secret_key, test_encryption_key)
payment = ApplePayment.new(flutterwave)
payment_charge = payment.initiate_charge(payload)


context "when a merchant tries to charge a customers via apple pay" do
it "should return a apple pay 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["data"]["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("Pending validation")
end

it 'should successfully return the auth model' do
payload_response = payment_charge
expect(payload_response["data"]["auth_model"]).to eq("APPLEPAY")
end

end
end
Loading