diff --git a/README.md b/README.md index 79f8a15..95335ff 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ A ruby gem for easy integration of [Paystack](https://paystack.co/). - ## Installation Add this line to your application's Gemfile: @@ -23,8 +22,6 @@ Or install it yourself as: ## Basic Usage - - ### Instantiate Paystack Object ```ruby @@ -40,9 +37,8 @@ A secure way is to set your public and private keys as environmental variables ` paystackObj = Paystack.new ``` -It throws a `PaystackBadKeyError` when either of the keys are invalid or cannot be found as environment variables. - +It throws a `PaystackBadKeyError` when either of the keys are invalid or cannot be found as environment variables. ### Initialize transaction and get Authorization URL @@ -56,9 +52,8 @@ It throws a `PaystackBadKeyError` when either of the keys are invalid or cannot ) auth_url = result['data']['authorization_url'] ``` -NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira` - +NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira` ### Charge using Authorization code for returning customers @@ -72,12 +67,8 @@ NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira` ) ``` - - ## Transactions - - ### List transactions ```ruby @@ -108,7 +99,6 @@ NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira` ``` - ### Get transaction totals ```ruby @@ -118,10 +108,8 @@ NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira` ``` - ## Customers - ### List Customers ```ruby @@ -228,7 +216,6 @@ NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira` ``` - ## Subscriptions ### Create new subscription @@ -280,7 +267,6 @@ NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira` ``` - ## Split Payments This Gem is also aware of the API calls that allow you to perform split payments on Paystack. The [Paystack documentation on split payments](https://developers.paystack.co/docs/split-payments-overview) can get you started. Below are some sample calls for [subaccounts](https://developers.paystack.co/docs/create-subaccount) and [banks](https://developers.paystack.co/docs/list-banks). @@ -352,6 +338,7 @@ This Gem is also aware of the API calls that allow you to perform split payments ``` ## Settlements + Fetch settlements made to your bank accounts and the bank accounts for your subaccounts ### List settlements @@ -396,8 +383,6 @@ The funds transfers feature enables you send money directly from your paystack b ``` - - ### Bulk transfer ```ruby @@ -421,7 +406,6 @@ The funds transfers feature enables you send money directly from your paystack b ``` - ### List transfers ```ruby @@ -454,7 +438,6 @@ The funds transfers feature enables you send money directly from your paystack b ``` - ## Transfer Recipients ### Create new recipient @@ -556,7 +539,6 @@ The funds transfers feature enables you send money directly from your paystack b ``` - ### Fetch refund ```ruby @@ -566,9 +548,51 @@ The funds transfers feature enables you send money directly from your paystack b ``` +## Verification + +### Resolve Account + +Confirm an account belongs to the right customer + +```ruby +verification = PaystackVerification.new(paystackObj) + +account_number = "0022728151" +bank_code = "063" +resolve_account = verification.resolveAccount(account_number, bank_code) +``` + +### Validate Account + +Confirm the authenticity of a customer's account number before sending money + +```ruby +verification = PaystackVerification.new(paystackObj) + +data = { + "bank_code": "632005", + "country_code": "ZA", + "account_number": "0123456789", + "account_name": "Ann Bron", + "account_type": "personal", + "document_type": "identityNumber", + "document_number": "1234567890123" +} +validate_account = verification.validateAccount(data) +``` + +### Resolve Card Bin + +```ruby +verification = PaystackVerification.new(paystack) + +bin = "539983" # first 6 characters of card +resolve_card_bin = verification.resolveCardBin(bin) +``` + ## Static methods -`PaystackTransactions`, `PaystackCustomers`, `PaystackPlans`, `PaystackSubaccounts`, `PaystackRefunds`, `PaystackBanks` , `PaystackSubscriptions` , `PaystackSettlements`, `PaystackBalance`, and `PaystackTransfers` methods can be called statically, You just need to pass the paystack object as the first parameter e.g. `verify` method in `PaystackTransactions` can be called like this +`PaystackTransactions`, `PaystackCustomers`, `PaystackPlans`, `PaystackSubaccounts`, `PaystackRefunds`, `PaystackBanks` , `PaystackSubscriptions` , `PaystackSettlements`, `PaystackBalance`, `PaystackTransfers`, and `PaystackVerification` methods can be called statically, You just need to pass the paystack object as the first parameter e.g. `verify` method in `PaystackTransactions` can be called like this ```ruby @@ -578,14 +602,10 @@ The funds transfers feature enables you send money directly from your paystack b ``` - - - ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/IkoroVictor/paystack-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. - ## License The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). diff --git a/lib/paystack.rb b/lib/paystack.rb index 21e1ea2..82cfa97 100644 --- a/lib/paystack.rb +++ b/lib/paystack.rb @@ -14,6 +14,7 @@ require 'paystack/objects/transfers.rb' require 'paystack/objects/subaccounts.rb' require 'paystack/objects/refunds.rb' +require 'paystack/objects/verification.rb' class Paystack attr_reader :public_key, :private_key diff --git a/lib/paystack/modules/api.rb b/lib/paystack/modules/api.rb index 455ed78..2098b73 100644 --- a/lib/paystack/modules/api.rb +++ b/lib/paystack/modules/api.rb @@ -12,4 +12,7 @@ module API TRANSFER_PATH = "/transfer" SETTLEMENT_PATH = "/settlement" REFUND_PATH = "/refund" + RESOLVE_PATH = "/resolve" + VALIDATE_PATH = "/validate" + DECISION_PATH = "/decision" end diff --git a/lib/paystack/objects/verification.rb b/lib/paystack/objects/verification.rb new file mode 100644 index 0000000..eb613e3 --- /dev/null +++ b/lib/paystack/objects/verification.rb @@ -0,0 +1,32 @@ +require 'paystack/objects/base.rb' + +class PaystackVerification < PaystackBaseObject + def resolveAccount(account_number, bank_code) + return PaystackVerification.resolveAccount(@paystack, account_number, bank_code) + end + + def validateAccount(args) + return PaystackVerification.validateAccount(@paystack, args) + end + + def resolveCardBin(bin) + return PaystackVerification.resolveCardBin(@paystack, bin) + end + +# => Public Static Methods + + def PaystackVerification.resolveAccount(paystackObj, account_number, bank_code) + path = "#{API::BANK_PATH}#{API::RESOLVE_PATH}?account_number=#{account_number}&bank_code=#{bank_code}" + initGetRequest(paystackObj, path) + end + + def PaystackVerification.validateAccount(paystackObj, data) + path = "#{API::BANK_PATH}#{API::VALIDATE_PATH}" + initPostRequest(paystackObj, path, data, true) + end + + def PaystackVerification.resolveCardBin(paystackObj, bin) + path = "#{API::DECISION_PATH}/bin/#{bin}" + initGetRequest(paystackObj, path) + end +end diff --git a/lib/paystack/version.rb b/lib/paystack/version.rb index e9c0317..26a6aa0 100644 --- a/lib/paystack/version.rb +++ b/lib/paystack/version.rb @@ -1,3 +1,3 @@ class Paystack - VERSION = "0.1.10" + VERSION = "0.1.20" end diff --git a/spec/paystack_customers_spec.rb b/spec/paystack_customers_spec.rb index 2884ec3..565fe0d 100644 --- a/spec/paystack_customers_spec.rb +++ b/spec/paystack_customers_spec.rb @@ -4,7 +4,7 @@ public_test_key = "pk_test_ea7c71f838c766922873f1dd3cc529afe13da1c0" private_test_key = "sk_test_40e9340686e6187697f8309dbae57c002bb16dd0" - + describe PaystackCustomers do it "should return a valid customers object" do paystack = Paystack.new(public_test_key, private_test_key) @@ -27,7 +27,7 @@ list = customers.list(1) expect(list.nil?).to eq false temp = list["data"][0] - puts temp.inspect + # puts temp.inspect hash=customers.get(temp['customer_code']) expect(hash.nil?).to eq false expect(hash['data']['customer_code'].nil?).to eq false @@ -49,13 +49,12 @@ paystack = Paystack.new(public_test_key, private_test_key) customers = PaystackCustomers.new(paystack) expect(customers.nil?).to eq false - temp = Random.new_seed.to_s + temp = Random.new_seed.to_s hash=customers.create(:first_name => "#{temp[0..6]}-person", :last_name => "Ogbonge", :phone => "+23470#{temp[0..6]}",:email => "#{temp[0..6]}@gmail.com") - puts hash + # puts hash expect(hash.nil?).to eq false expect(hash['data']['id'].nil?).to eq false end end - diff --git a/spec/paystack_subaccounts_spec.rb b/spec/paystack_subaccounts_spec.rb index 6a38150..617a9ff 100644 --- a/spec/paystack_subaccounts_spec.rb +++ b/spec/paystack_subaccounts_spec.rb @@ -50,7 +50,7 @@ expect(subaccounts.nil?).to eq false temp = Random.new_seed.to_s hash=subaccounts.create(:business_name => "#{temp[0..6]}-business", :settlement_bank => "011", :account_number => "0000000000", :percentage_charge => 2.5) - puts hash + # puts hash expect(hash.nil?).to eq false expect(hash['data']['id'].nil?).to eq false end diff --git a/spec/paystack_subscriptions_spec.rb b/spec/paystack_subscriptions_spec.rb index 33c3d76..bde72ca 100644 --- a/spec/paystack_subscriptions_spec.rb +++ b/spec/paystack_subscriptions_spec.rb @@ -38,9 +38,9 @@ hash = subscriptions.get(subscription['data']['id']) - - puts hash - + + # puts hash + expect(hash.nil?).to eq false expect(hash['data']['id'].nil?).to eq false end @@ -67,8 +67,8 @@ :customer => "lol@gmail.com", :plan => plan["data"]["plan_code"] ) - - puts hash + + # puts hash expect(hash.nil?).to eq false expect(hash['data']['id'].nil?).to eq false diff --git a/spec/paystack_transfers_spec.rb b/spec/paystack_transfers_spec.rb index cd7814c..1b94f4b 100644 --- a/spec/paystack_transfers_spec.rb +++ b/spec/paystack_transfers_spec.rb @@ -4,7 +4,7 @@ public_test_key = "pk_test_ea7c71f838c766922873f1dd3cc529afe13da1c0" private_test_key = "sk_test_40e9340686e6187697f8309dbae57c002bb16dd0" - + describe PaystackTransfers do it "should return a valid transfer object" do paystack = Paystack.new(public_test_key, private_test_key) @@ -84,4 +84,4 @@ -end \ No newline at end of file +end diff --git a/spec/paystack_verification_spec.rb b/spec/paystack_verification_spec.rb new file mode 100644 index 0000000..00ecce0 --- /dev/null +++ b/spec/paystack_verification_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' +require 'paystack/objects/verification.rb' +require 'paystack.rb' + +public_test_key = "pk_test_2f32c8e5478b41e9f737de5a64c5ab516cd57946" +private_test_key = "sk_test_cec422efd6cc29427383acdb517ce0bd43e6247c" + +describe PaystackVerification do + + it "should return a valid verfication object" do + paystack = Paystack.new(public_test_key, private_test_key) + verification = PaystackVerification.new(paystack) + expect(verification.nil?).to eq false + end + + it "should resolve customer account details" do + paystack = Paystack.new(public_test_key, private_test_key) + verification = PaystackVerification.new(paystack) + + account_number = "9010761375" # personal account but no forseen risk + bank_code = "999992" # bank code for Opay + resolve_account = verification.resolveAccount(account_number, bank_code) + + account_info = resolve_account['data'] + expect(account_info.nil?).to eq false + expect(account_info['account_number']).to eq "9010761375" + expect(account_info['account_name']).to eq "OLUWAGBAMILA ABIODUN AREMU" + end + + it "should return object for validateAccount " do + paystack = Paystack.new(public_test_key, private_test_key) + verification = PaystackVerification.new(paystack) + + # gotten from paystack docs + data = { + "bank_code": "632005", + "country_code": "ZA", + "account_number": "0123456789", + "account_name": "Ann Bron", + "account_type": "personal", + "document_type": "identityNumber", + "document_number": "1234567890123" + } + validate_account = verification.validateAccount(data) + + validate_account_data = validate_account['data'] + expect(validate_account_data.nil?).to eq false + end + + it "should return object for resolveCardBin " do + paystack = Paystack.new(public_test_key, private_test_key) + verification = PaystackVerification.new(paystack) + + bin = "539983" # gotten from paystack docs + resolve_card_bin = verification.resolveCardBin(bin) + + resolve_card_bin_data = resolve_card_bin['data'] + expect(resolve_card_bin_data.nil?).to eq false + end + +end