paystack 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bfffac1071ccab650bec0e73af7b5caf8ff6f57
4
- data.tar.gz: 5c8125e3f70f8321fc66c5d5adeb758c8cad6368
3
+ metadata.gz: ae8e6284abf3217caed4431540242dcc7ec79fac
4
+ data.tar.gz: ff9e3e54dcf80cd650cf1315ee307a9eac5a84d6
5
5
  SHA512:
6
- metadata.gz: 7d2e673cb05a9bd987450e392138af759619b9e855b56c419d9672bb9855ac5b1dc56af7ff99c877c4ced46c45b38021d2da81ed7ad1c124a00e125e2ebbdd71
7
- data.tar.gz: de3ec225ab575e393e03739a916c1b6ed5d32d1d2cebfb9f24f4f30dfba489c0f798ca8004c6604c469befcd8ed5c5630e233b681e7d25da135578103491ad1a
6
+ metadata.gz: fa1c3e4e8ac03be75742784b883bad76cb2c9c570c59dfcf6f9371c9017688727cfc1468f8ca86bbe23bc08c9a03732d9b1ceeeb99fa8f2c579bf9b97aa0d73e
7
+ data.tar.gz: 231967b9e5724e016da55b3c1db6618d6184e9c8415c508963da8286eee2be83de8ac360f27ac1fa12b0946837ac0068482dc745c96fcd04a0462861df0d1088
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --color
2
- --require spec_helper
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,16 @@
1
+ sudo: required
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+ before_install: gem install bundler
6
+ cache:
7
+ directories:
8
+ - vendor/bundle
9
+
10
+ script:
11
+ - rspec
12
+
13
+ deploy:
14
+ provider: rubygems
15
+ api_key: "bcc5d3ff98af614e950b21a2df77af20"
16
+ gem: paystack
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Paystack
2
2
 
3
+ [![Build Status](https://travis-ci.org/IkoroVictor/paystack-ruby.svg?branch=master)](https://travis-ci.org/IkoroVictor/paystack-ruby) [![Gem Version](https://badge.fury.io/rb/paystack.svg)](https://badge.fury.io/rb/paystack)
3
4
 
4
- A ruby gem for easy integration of [Paystack](https://paystack.co/).
5
+ A ruby gem for easy integration of [Paystack](https://paystack.co/).
5
6
 
6
7
 
7
8
  ## Installation
@@ -43,23 +44,6 @@ It throws a `PaystackBadKeyError` when either of the keys are invalid or cannot
43
44
 
44
45
 
45
46
 
46
- ### Instantiate a Card object
47
-
48
- ```ruby
49
- card = new PaystackCard(
50
- :number => "304402040400400022",
51
- :cvc => "888",
52
- :expiryMonth => "07",
53
- :expiryYear => "19"
54
- )
55
-
56
- isvalid = card.isValidCard
57
- ```
58
- The `isValidCard` method determines validity of the card i.e. Expiry status, Luhn checksum validity etc.
59
- All card values/fields should be String literals.
60
-
61
-
62
-
63
47
  ### Initialize transaction and get Authorization URL
64
48
 
65
49
  ```ruby
@@ -70,7 +54,7 @@ All card values/fields should be String literals.
70
54
  :amount => 300000,
71
55
  :email => "xxxxxx@gmail.com",
72
56
  )
73
- auth_url = results['data']['authorization_url']
57
+ auth_url = result['data']['authorization_url']
74
58
  ```
75
59
  NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira`
76
60
 
@@ -108,7 +92,7 @@ NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira`
108
92
 
109
93
  ```ruby
110
94
 
111
- transaction_id = ""123456778""
95
+ transaction_id = "123456778"
112
96
  transactions = PaystackTransactions.new(paystackObj)
113
97
  result = transactions.get(transaction_id)
114
98
 
@@ -233,7 +217,7 @@ NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira`
233
217
 
234
218
  ```ruby
235
219
 
236
- plan_id = ""123456778""
220
+ plan_id = ""123456778"
237
221
  plans = PaystackPlans.new(paystackObj)
238
222
  result = plans.update(
239
223
  plan_id,
@@ -245,8 +229,60 @@ NOTE: Amount is in kobo i.e. `100000 = 100000 kobo = 1000 naira`
245
229
  ```
246
230
 
247
231
 
232
+ ## Subscriptions
233
+
234
+ ### Create new subscription
235
+
236
+ ```ruby
237
+
238
+ subscriptions = PaystackSubscriptions.new(paystackObj)
239
+ result = subscriptions.create(
240
+
241
+ :customer => "customer@email.com",
242
+ :plan => "123557", #plan id
243
+ :amount => 30000 #in KOBO
244
+ )
245
+
246
+ ```
247
+
248
+ ### Get subscription detail
249
+
250
+ ```ruby
251
+
252
+ subscription_id = "123456778"
253
+ subscriptions = PaystackSubscriptions.new(paystackObj)
254
+ result = subscriptions.get(subscription_id)
255
+ subscription = result['data']
256
+
257
+ ```
258
+
259
+ ### Enable subscription
260
+
261
+ ```ruby
262
+
263
+ subscriptions = PaystackSubscriptions.new(paystackObj)
264
+ result = subscriptions.enable(
265
+ :code => "12328833",
266
+ :token => "EWFWKFJWE" #user email token
267
+ )
268
+
269
+ ```
270
+
271
+ ### Disable subscription
272
+
273
+ ```ruby
274
+
275
+ subscriptions = PaystackSubscriptions.new(paystackObj)
276
+ result = subscriptions.disable(
277
+ :code => "12328833",
278
+ :token => "EWFWKFJWE" #user email token
279
+ )
280
+
281
+ ```
282
+
283
+
248
284
  ## Static methods
249
- `PaystackTransactions`, `PaystackCustomers` and `PaystackPlans` 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
285
+ `PaystackTransactions`, `PaystackCustomers`, `PaystackPlans` and `PaystackSubscriptions` 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
250
286
 
251
287
 
252
288
  ```ruby
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new
4
+ RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task :default => :spec
7
- task :test => :spec
File without changes
data/bin/setup CHANGED
File without changes
@@ -1,54 +1,55 @@
1
- require 'rest-client'
2
- require 'paystack/error.rb'
3
- require 'paystack/modules/api.rb'
4
- require 'paystack/utils/utils.rb'
5
- require 'paystack/objects/card.rb'
6
- require 'paystack/objects/customers.rb'
7
- require 'paystack/objects/plans.rb'
8
- require 'paystack/objects/transactions.rb'
9
-
10
-
11
- class Paystack
12
- attr_reader :public_key, :private_key
13
-
14
- def initialize paystack_public_key=nil, paystack_private_key=nil
15
- if(paystack_public_key.nil?)
16
- @public_key = ENV['PAYSTACK_PUBLIC_KEY']
17
-
18
- else
19
- @public_key = paystack_public_key
20
- end
21
-
22
- if(paystack_private_key.nil?)
23
- @private_key = ENV['PAYSTACK_PRIVATE_KEY']
24
- else
25
- @private_key = paystack_private_key
26
- end
27
-
28
- unless !@public_key.nil?
29
- raise PaystackBadKeyError, "No public key supplied and couldn't find any in environment variables. Make sure to set public key as an environment variable PAYSTACK_PUBLIC_KEY"
30
- end
31
- unless @public_key[0..2] == 'pk_'
32
- raise PaystackBadKeyError, "Invalid public key #{@public_key}"
33
- end
34
-
35
- unless !@private_key.nil?
36
- raise PaystackBadKeyError, "No private key supplied and couldn't find any in environment variables. Make sure to set private key as an environment variable PAYSTACK_PRIVATE_KEY"
37
- end
38
- unless @private_key[0..2] == 'sk_'
39
- raise PaystackBadKeyError, "Invalid private key #{@private_key}"
40
- end
41
-
42
-
43
- end
44
-
45
-
46
- def setPublicKey public_key
47
- @public_key = public_key
48
- end
49
-
50
- def setPrivateKey public_key
51
- @public_key = public_key
52
- end
53
-
54
- end
1
+ require 'rest-client'
2
+ require 'paystack/error.rb'
3
+ require 'paystack/modules/api.rb'
4
+ require 'paystack/utils/utils.rb'
5
+ require 'paystack/objects/card.rb'
6
+ require 'paystack/objects/customers.rb'
7
+ require 'paystack/objects/plans.rb'
8
+ require 'paystack/objects/subscriptions.rb'
9
+ require 'paystack/objects/transactions.rb'
10
+
11
+
12
+ class Paystack
13
+ attr_reader :public_key, :private_key
14
+
15
+ def initialize paystack_public_key=nil, paystack_private_key=nil
16
+ if (paystack_public_key.nil?)
17
+ @public_key = ENV['PAYSTACK_PUBLIC_KEY']
18
+ else
19
+ @public_key = paystack_public_key
20
+ end
21
+
22
+ if (paystack_private_key.nil?)
23
+ @private_key = ENV['PAYSTACK_PRIVATE_KEY']
24
+ else
25
+ @private_key = paystack_private_key
26
+ end
27
+
28
+ unless !@public_key.nil?
29
+ raise PaystackBadKeyError, "No public key supplied and couldn't find any in environment variables. Make sure to set public key as an environment variable PAYSTACK_PUBLIC_KEY"
30
+ end
31
+ unless @public_key[0..2] == 'pk_'
32
+ raise PaystackBadKeyError, "Invalid public key #{@public_key}"
33
+ end
34
+
35
+ unless !@private_key.nil?
36
+ raise PaystackBadKeyError, "No private key supplied and couldn't find any in environment variables. Make sure to set private key as an environment variable PAYSTACK_PRIVATE_KEY"
37
+ end
38
+ unless @private_key[0..2] == 'sk_'
39
+ raise PaystackBadKeyError, "Invalid private key #{@private_key}"
40
+ end
41
+
42
+
43
+ end
44
+
45
+ #TODO delete if not used
46
+ def setPublicKey public_key
47
+ @public_key = public_key
48
+ end
49
+
50
+ def setPrivateKey public_key
51
+ @public_key = public_key
52
+ end
53
+
54
+ end
55
+
@@ -1,13 +1,12 @@
1
-
2
- class PaystackServerError < StandardError
3
- attr_reader :response
4
- def initialize(response=nil)
5
- @response = response
6
- end
7
- end
8
-
9
- class PaystackCardError < StandardError
10
- end
11
-
12
- class PaystackBadKeyError < StandardError
1
+ class PaystackServerError < StandardError
2
+ attr_reader :response
3
+ def initialize(response=nil)
4
+ @response = response
5
+ end
6
+ end
7
+
8
+ class PaystackCardError < StandardError
9
+ end
10
+
11
+ class PaystackBadKeyError < StandardError
13
12
  end
@@ -1,7 +1,8 @@
1
- module API
2
- BASE_URL = "https://api.paystack.co"
3
- TOKEN_URL ='https://standard.paystack.co/bosco/createmobiletoken'
4
- TRANSACTION_PATH = "/transaction"
5
- PLAN_PATH = "/plan"
6
- CUSTOMER_PATH = "/customer"
7
- end
1
+ module API
2
+ BASE_URL = "https://api.paystack.co"
3
+ TOKEN_URL ='https://standard.paystack.co/bosco/createmobiletoken'
4
+ TRANSACTION_PATH = "/transaction"
5
+ PLAN_PATH = "/plan"
6
+ CUSTOMER_PATH = "/customer"
7
+ SUBSCRIPTION_PATH = "/subscription"
8
+ end
@@ -1,102 +1,103 @@
1
- class PaystackBaseObject
2
-
3
- attr_reader :paystack
4
-
5
- def initialize(paystackObj)
6
- unless !paystackObj.nil?
7
- raise ArgumentError, "Paystack object cannot be nil!!"
8
- end
9
- @paystack = paystackObj
10
- end
11
-
12
- protected
13
- # =>Static methods
14
- def self.initGetRequest(paystackObj, url)
15
- result = nil
16
- begin
17
- response = RestClient.get "#{API::BASE_URL}#{url}" , :Authorization => "Bearer #{paystackObj.private_key}", :content_type => :json, :accept => :json
18
- unless (response.code == 200 || response.code == 201)
19
- raise PaystackServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
20
- end
21
- result = JSON.parse(response.body)
22
- unless(result['status'] != 0 )
23
- raise PaystackServerError.new(response), "Server Message: #{result['message']}"
24
- end
25
-
26
- rescue JSON::ParserError => jsonerr
27
- raise PaystackServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"
28
-
29
- rescue PaystackServerError => e
30
- Utils.serverErrorHandler(e)
31
- end
32
- return result
33
- end
34
-
35
- def self.initPostRequest(paystackObj, url, data = {}, json=false )
36
- result = nil
37
- begin
38
- if !json
39
- response = RestClient.post "#{API::BASE_URL}#{url}" , data, :Authorization => "Bearer #{paystackObj.private_key}"
40
- else
41
- response = RestClient.post "#{API::BASE_URL}#{url}" , data.to_json, :Authorization => "Bearer #{paystackObj.private_key}", :content_type => :json, :accept => :json
42
-
43
- end
44
- unless (response.code == 200 || response.code == 201)
45
- raise PaystackServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
46
- end
47
- result = JSON.parse(response.body)
48
- unless(result['status'] != 0 )
49
- raise PaystackServerError.new(response), "Server Message: #{result['message']}"
50
- end
51
-
52
- rescue JSON::ParserError => jsonerr
53
- raise PaystackServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"
54
-
55
- rescue PaystackServerError => e
56
- Utils.serverErrorHandler(e)
57
- end
58
- return result
59
- end
60
-
61
- def self.initPutRequest(paystackObj, url, data = {} )
62
- result = nil
63
- begin
64
- response = RestClient.put "#{API::BASE_URL}#{url}" , data, :Authorization => "Bearer #{paystackObj.private_key}"
65
- unless (response.code == 200 || response.code == 201)
66
- raise PaystackServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
67
- end
68
- result = JSON.parse(response.body)
69
- unless(result['status'] != 0 )
70
- raise PaystackServerError.new(response), "Server Message: #{result['message']}"
71
- end
72
-
73
- rescue JSON::ParserError => jsonerr
74
- raise PaystackServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"
75
-
76
- rescue PaystackServerError => e
77
- Utils.serverErrorHandler(e)
78
- end
79
- return result
80
- end
81
-
82
- def self.initDeleteRequest(paystackObj, url)
83
- result = nil
84
- begin
85
- response = RestClient.delete "#{API::BASE_URL}#{url}" , :Authorization => "Bearer #{paystackObj.private_key}"
86
- unless (response.code == 200 || response.code == 201)
87
- raise PaystackServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
88
- end
89
- result = JSON.parse(response.body)
90
- unless(result['status'] != 0 )
91
- raise PaystackServerError.new(response), "Server Message: #{result['message']}"
92
- end
93
-
94
- rescue JSON::ParserError => jsonerr
95
- raise PaystackServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"
96
-
97
- rescue PaystackServerError => e
98
- Utils.serverErrorHandler(e)
99
- end
100
- return result
101
- end
102
- end
1
+ class PaystackBaseObject
2
+ require 'json'
3
+
4
+ attr_reader :paystack
5
+
6
+ def initialize(paystackObj)
7
+ unless !paystackObj.nil?
8
+ raise ArgumentError, "Paystack object cannot be nil!!"
9
+ end
10
+ @paystack = paystackObj
11
+ end
12
+
13
+ protected
14
+ # =>Static methods
15
+ def self.initGetRequest(paystackObj, url)
16
+ result = nil
17
+ begin
18
+ response = RestClient.get "#{API::BASE_URL}#{url}" , :Authorization => "Bearer #{paystackObj.private_key}", :content_type => :json, :accept => :json
19
+ unless (response.code == 200 || response.code == 201)
20
+ raise PaystackServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
21
+ end
22
+ result = JSON.parse(response.body)
23
+ unless(result['status'] != 0 )
24
+ raise PaystackServerError.new(response), "Server Message: #{result['message']}"
25
+ end
26
+
27
+ rescue JSON::ParserError => jsonerr
28
+ raise PaystackServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"
29
+
30
+ rescue PaystackServerError => e
31
+ Utils.serverErrorHandler(e)
32
+ end
33
+ return result
34
+ end
35
+
36
+ def self.initPostRequest(paystackObj, url, data = {}, json=false )
37
+ result = nil
38
+ begin
39
+ if !json
40
+ response = RestClient.post "#{API::BASE_URL}#{url}" , data, :authorization => "Bearer #{paystackObj.private_key}"
41
+ else
42
+ response = RestClient.post "#{API::BASE_URL}#{url}" , data.to_json, :authorization => "Bearer #{paystackObj.private_key}", :content_type => :json, :accept => :json
43
+
44
+ end
45
+ unless (response.code == 200 || response.code == 201)
46
+ raise PaystackServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
47
+ end
48
+ result = JSON.parse(response.body)
49
+ unless(result['status'] != 0 )
50
+ raise PaystackServerError.new(response), "Server Message: #{result['message']}"
51
+ end
52
+
53
+ rescue JSON::ParserError => jsonerr
54
+ raise PaystackServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"
55
+
56
+ rescue PaystackServerError => e
57
+ Utils.serverErrorHandler(e)
58
+ end
59
+ return result
60
+ end
61
+
62
+ def self.initPutRequest(paystackObj, url, data = {} )
63
+ result = nil
64
+ begin
65
+ response = RestClient.put "#{API::BASE_URL}#{url}" , data, :Authorization => "Bearer #{paystackObj.private_key}"
66
+ unless (response.code == 200 || response.code == 201)
67
+ raise PaystackServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
68
+ end
69
+ result = JSON.parse(response.body)
70
+ unless(result['status'] != 0 )
71
+ raise PaystackServerError.new(response), "Server Message: #{result['message']}"
72
+ end
73
+
74
+ rescue JSON::ParserError => jsonerr
75
+ raise PaystackServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"
76
+
77
+ rescue PaystackServerError => e
78
+ Utils.serverErrorHandler(e)
79
+ end
80
+ return result
81
+ end
82
+
83
+ def self.initDeleteRequest(paystackObj, url)
84
+ result = nil
85
+ begin
86
+ response = RestClient.delete "#{API::BASE_URL}#{url}" , :Authorization => "Bearer #{paystackObj.private_key}"
87
+ unless (response.code == 200 || response.code == 201)
88
+ raise PaystackServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
89
+ end
90
+ result = JSON.parse(response.body)
91
+ unless(result['status'] != 0 )
92
+ raise PaystackServerError.new(response), "Server Message: #{result['message']}"
93
+ end
94
+
95
+ rescue JSON::ParserError => jsonerr
96
+ raise PaystackServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"
97
+
98
+ rescue PaystackServerError => e
99
+ Utils.serverErrorHandler(e)
100
+ end
101
+ return result
102
+ end
103
+ end