paynow_sdk 1.0.0 → 1.0.1

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
  SHA256:
3
- metadata.gz: 4419acd2239e550cc8d40002597a688f835f912fb4fe216739a4ca338302cb0b
4
- data.tar.gz: e450025e4642c4a5e3f6cceb17499eeb0f4fc9a1290d8f4e8d42dd89cff323b9
3
+ metadata.gz: 45d0090653691c2ec9f007f763b1d21bf13e5f52818420d2ade1c9ea4195d750
4
+ data.tar.gz: 55f27a4f21ffdba2ede5cba3519a0916aedd5627ed0aaec34f31f3caca4b5292
5
5
  SHA512:
6
- metadata.gz: 07d38729dfc4dfe3a805f217ad1cd4afba264655a3618627548689983b71b6b9d9ad55758ae37fa5367c964884aacc96f99460ef4df081d381db6a198891fd21
7
- data.tar.gz: 457c0ff50c48bab21a5bf51689c63949cf4b8f92764d353258aa0804447ab566e33c1aa48b30cbf2b2cc26f7f1f78e72c2527f2c2095883ef2f1a51a98a52765
6
+ metadata.gz: b1920b10a9af39aa0b43df4da7c6cd29c71c63866b3ee635958c0b02a9d263cc65124977a43ab1fb3e1037394b4f78ffa83c36d0508a5d160cfb8a8ddc601a28
7
+ data.tar.gz: b517952320e9503de2c34fa4c44ec609db427bba82b1a8c2b4ff9a43deb95dd42297b6eeb2dee0df18140c7239d83c87ac15effb101e278f9285ad5c8df42934
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  /_yardoc/
4
4
  /coverage/
5
5
  /doc/
6
+ /.vscode/
6
7
  /pkg/
7
8
  /spec/reports/
8
9
  /tmp/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paynow_sdk (1.0.0)
4
+ paynow_sdk (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,4 @@
1
- # PaynowSdk
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/paynow_sdk`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
1
+ # PaynowSdk Ruby gem
6
2
 
7
3
  ## Installation
8
4
 
@@ -22,15 +18,139 @@ Or install it yourself as:
22
18
 
23
19
  ## Usage
24
20
 
25
- TODO: Write usage instructions here
21
+ Create an instance of the Paynow class optionally setting the result and return url(s)
26
22
 
27
- ## Development
23
+ ```ruby
24
+ paynow = Paynow.new(
25
+ 'INTEGRATION_ID',
26
+ 'INTEGRATION_KEY',
27
+ 'http://returnurl.com',
28
+ 'http://resulturl.com'
29
+ )
30
+ ```
28
31
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+ Create a new payment passing in the reference for that payment (e.g invoice id, or anything that you can use to identify the transaction and the user's email address
30
33
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+ ```ruby
35
+ payment = paynow.create_payment('Order #100', 'test@example.com')
36
+ ```
32
37
 
33
- ## Contributing
38
+ You can then start adding items to the payment
39
+
40
+ ```ruby
41
+ # Passing in the name of the item and the price of the item
42
+ payment.add('Bananas', 2.50)
43
+ payment.add('Apples', 3.40)
44
+ ```
45
+
46
+ When you're finally ready to send your payment to Paynow, you can use the `send` method in the `paynow` object.
47
+
48
+ ```ruby
49
+ # Save the response from paynow in a variable
50
+ response = paynow.send(payment)
51
+ ```
52
+
53
+ The response from Paynow will be have some useful information like whether the request was successful or not. If it was, for example, it contains the url to redirect the user so they can make the payment.
54
+
55
+ If request was successful, you should consider saving the poll url sent from Paynow in the database
56
+
57
+ ```ruby
58
+ if response.success
59
+ # The link to redirect the user to paynow to make the payment
60
+ link = response.redirect_url
61
+ # Get the poll url (used to check the status of a transaction). You might want to save this in your DB
62
+ pollUrl = response.poll_url
63
+ end
64
+ ```
65
+
66
+ ---
67
+
68
+ > Mobile Transactions
69
+
70
+ If you want to send an express (mobile) checkout request instead, the only thing that differs is the last step. You make a call to the `send_mobile` in the `paynow` object
71
+ instead of the `send` method.
72
+
73
+ The `send_mobile` method unlike the `send` method takes in two additional arguments i.e The phone number to send the payment request to and the mobile money method to use for the request. **Note that currently only ecocash is supported**
74
+
75
+ ```ruby
76
+ # Save the response from paynow in a variable
77
+ response = paynow.send_mobile(payment, '0777777777', 'ecocash')
78
+ ```
79
+
80
+ The response object is almost identical to the one you get if you send a normal request. With a few differences, firstly, you don't get a url to redirect to. Instead you instructions (which ideally should be shown to the user instructing them how to make payment on their mobile phone)
81
+
82
+ ```ruby
83
+ if response.success
84
+ # Get the poll url (used to check the status of a transaction). You might want to save this in your DB
85
+ poll_url = response.poll_url
86
+
87
+ instructions = response.instructions
88
+ end
89
+ ```
90
+
91
+ # Checking transaction status
92
+
93
+ The SDK exposes a handy method that you can use to check the status of a transaction. Once you have instantiated the Paynow class.
34
94
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/paynow_sdk.
95
+ ```ruby
96
+ # Check the status of the transaction with the specified poll url
97
+ # Now you see why you need to save that url ;-)
98
+ status = paynow.check_transaction_status(poll_url)
99
+
100
+ if status.paid
101
+ # Yay! Transaction was paid for. Update transaction?
102
+ else
103
+ # Handle that
104
+ end
105
+ ```
106
+
107
+ # Full Usage Example
108
+
109
+ ```ruby
110
+ gem 'paynow_sdk'
111
+ ```
112
+
113
+ And then execute:
114
+
115
+ ```ruby
116
+ $ bundle install
117
+ ```
118
+
119
+ Or install it yourself as:
120
+
121
+ ```ruby
122
+ $ gem install paynow_sdk
123
+ ```
124
+
125
+ ```ruby
126
+ paynow = Paynow.new(
127
+ 'INTEGRATION_ID',
128
+ 'INTEGRATION_KEY',
129
+ 'http://returnurl.com',
130
+ 'http://resulturl.com'
131
+ )
132
+
133
+ payment = paynow.create_payment('Order', 'test@example.com')
134
+
135
+ payment.add('Payment for stuff', 1)
136
+
137
+ response = paynow.send(payment)
138
+
139
+
140
+ if response.success
141
+ # The link to redirect the user to paynow to make the payment
142
+ link = response.redirect_url
143
+
144
+ poll_url = response.poll_url
145
+
146
+ print "Poll Url: " + poll_url
147
+
148
+ status = paynow.check_transaction_status(poll_url)
149
+
150
+ print "Payment Status: " + status.status
151
+ end
152
+ ```
153
+
154
+ ## Contributing
36
155
 
156
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gitnyasha/paynow-ruby-sdk.
@@ -312,7 +312,7 @@ class Paynow
312
312
 
313
313
  request = Net::HTTP::Post.new(url)
314
314
  request["content-type"] = "application/x-www-form-urlencoded"
315
- request.body = data
315
+ request.body = {}
316
316
 
317
317
  response = http.request(request)
318
318
  response.read_body
@@ -1,3 +1,3 @@
1
1
  module PaynowSdk
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paynow_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - marshall nyasha chikari
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-24 00:00:00.000000000 Z
11
+ date: 2020-08-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: The gem includes modules and methods to make it easy for integrating
14
14
  paynow api to ruby apps.