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

Verification #26

Open
wants to merge 1 commit into
base: master
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
72 changes: 46 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

A ruby gem for easy integration of [Paystack](https://paystack.co/).


## Installation

Add this line to your application's Gemfile:
Expand All @@ -23,8 +22,6 @@ Or install it yourself as:

## Basic Usage



### Instantiate Paystack Object

```ruby
Expand All @@ -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

Expand All @@ -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

Expand All @@ -72,12 +67,8 @@ NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira`
)
```



## Transactions



### List transactions

```ruby
Expand Down Expand Up @@ -108,7 +99,6 @@ NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira`

```


### Get transaction totals

```ruby
Expand All @@ -118,10 +108,8 @@ NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira`

```


## Customers


### List Customers

```ruby
Expand Down Expand Up @@ -228,7 +216,6 @@ NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira`

```


## Subscriptions

### Create new subscription
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -396,8 +383,6 @@ The funds transfers feature enables you send money directly from your paystack b

```



### Bulk transfer

```ruby
Expand All @@ -421,7 +406,6 @@ The funds transfers feature enables you send money directly from your paystack b

```


### List transfers

```ruby
Expand Down Expand Up @@ -454,7 +438,6 @@ The funds transfers feature enables you send money directly from your paystack b

```


## Transfer Recipients

### Create new recipient
Expand Down Expand Up @@ -556,7 +539,6 @@ The funds transfers feature enables you send money directly from your paystack b

```


### Fetch refund

```ruby
Expand All @@ -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

Expand All @@ -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).
1 change: 1 addition & 0 deletions lib/paystack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/paystack/modules/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 32 additions & 0 deletions lib/paystack/objects/verification.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/paystack/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Paystack
VERSION = "0.1.10"
VERSION = "0.1.20"
end
9 changes: 4 additions & 5 deletions spec/paystack_customers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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

2 changes: 1 addition & 1 deletion spec/paystack_subaccounts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions spec/paystack_subscriptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -67,8 +67,8 @@
:customer => "[email protected]",
:plan => plan["data"]["plan_code"]
)
puts hash

# puts hash

expect(hash.nil?).to eq false
expect(hash['data']['id'].nil?).to eq false
Expand Down
4 changes: 2 additions & 2 deletions spec/paystack_transfers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -84,4 +84,4 @@



end
end
61 changes: 61 additions & 0 deletions spec/paystack_verification_spec.rb
Original file line number Diff line number Diff line change
@@ -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