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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +131 -11
- data/lib/paynow_sdk.rb +1 -1
- data/lib/paynow_sdk/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45d0090653691c2ec9f007f763b1d21bf13e5f52818420d2ade1c9ea4195d750
|
4
|
+
data.tar.gz: 55f27a4f21ffdba2ede5cba3519a0916aedd5627ed0aaec34f31f3caca4b5292
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1920b10a9af39aa0b43df4da7c6cd29c71c63866b3ee635958c0b02a9d263cc65124977a43ab1fb3e1037394b4f78ffa83c36d0508a5d160cfb8a8ddc601a28
|
7
|
+
data.tar.gz: b517952320e9503de2c34fa4c44ec609db427bba82b1a8c2b4ff9a43deb95dd42297b6eeb2dee0df18140c7239d83c87ac15effb101e278f9285ad5c8df42934
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
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
|
-
|
21
|
+
Create an instance of the Paynow class optionally setting the result and return url(s)
|
26
22
|
|
27
|
-
|
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
|
-
|
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
|
-
|
34
|
+
```ruby
|
35
|
+
payment = paynow.create_payment('Order #100', 'test@example.com')
|
36
|
+
```
|
32
37
|
|
33
|
-
|
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
|
-
|
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.
|
data/lib/paynow_sdk.rb
CHANGED
data/lib/paynow_sdk/version.rb
CHANGED
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.
|
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-
|
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.
|