paycorp_rails 0.0.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +73 -12
- data/lib/paycorp_rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c5adb753a0431799db86d9e308d2329d4ea91e2
|
4
|
+
data.tar.gz: 14873d08e5d8c2a2cb10df423e95d7724238e15d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a184e1e7c6d249becd3ca4556dbc4f7ee13e0b676db84f8eee56e8f72e63f2e6163fc0782b58873bbd1766ddd850c2f557ded1caeaa7244f1cd636f77233dcf
|
7
|
+
data.tar.gz: 64cceed991392d09b98b0b6a942a15d8e521cc132ce94127483c651d21233b5e53e1a83ba472e693cb3078dfd8c191c205b5709a437b849ac556d3856e3e78af
|
data/README.md
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
# PaycorpRails
|
2
|
+
[](https://badge.fury.io/rb/paycorp_rails)
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
4
|
+
This gem will integrate the Paycorp payment gateway with your Rails app. If you face any issues, place them here : [github.com/LeafyCode/paycorp_rails/issues](https://github.com/LeafyCode/paycorp_rails/issues). You can also contact us directly : [leafycode.com/contact](http://leafycode.com/contact)
|
6
5
|
|
7
6
|
## Installation
|
8
|
-
|
9
7
|
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
@@ -14,28 +12,91 @@ gem 'paycorp_rails'
|
|
14
12
|
|
15
13
|
And then execute:
|
16
14
|
|
17
|
-
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
|
21
|
+
```
|
22
|
+
$ gem install paycorp_rails
|
23
|
+
```
|
22
24
|
|
23
25
|
## Usage
|
26
|
+
### Initialize the Gateway
|
27
|
+
To initialize the gateway, in your `config/application.rb` place the following code and make the necessary changes :
|
24
28
|
|
25
|
-
|
29
|
+
```ruby
|
30
|
+
config.after_initialize do
|
31
|
+
paycorp_options = {
|
32
|
+
client_id: 'CLIENT_ID',
|
33
|
+
hmac: 'HMAC',
|
34
|
+
auth_token: 'AUTH_TOKEN',
|
35
|
+
endpoint: 'ENDPOINT'
|
36
|
+
}
|
37
|
+
::PAYCORP_GATEWAY = PaycorpRails.new(paycorp_options)
|
38
|
+
end
|
39
|
+
```
|
26
40
|
|
27
|
-
|
41
|
+
Note : The `CLIENT_ID`, `HMAC`, `AUTH_TOKEN` and the `ENDPOINT` will be given to you by Paycorp.
|
42
|
+
|
43
|
+
### Initiate Payment
|
44
|
+
First, you need to send the transaction details to Paycorp and initiate the payment :
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
payment_options = {
|
48
|
+
msg_id: SecureRandom.uuid, # Better generate this and store in the model and then use that in here
|
49
|
+
amount: AMOUNT_IN_CENTS,
|
50
|
+
currency: 'LKR', # Currency
|
51
|
+
return_url: "RETURN_URL",
|
52
|
+
user_id: USER_ID, # For reference
|
53
|
+
css_url: 'ADDITIONAL_CSS'
|
54
|
+
}
|
55
|
+
|
56
|
+
response = PAYCORP_GATEWAY.initiate_payment(payment_options)
|
57
|
+
```
|
58
|
+
|
59
|
+
**amount** should be in cents. **css_url** : If you are using the iframe version, you can pass a css file to style the iframe. Make sure the file is served with HTTPS.
|
60
|
+
|
61
|
+
Store the `response` data in the model (Specially the `reqid` and the `paymentPageUrl`)
|
62
|
+
|
63
|
+
If you use the iframe method, use the `paymentPageUrl` for the iframe. If not, redirect the user to that url.
|
64
|
+
|
65
|
+
### Complete Payment
|
66
|
+
When the user complete the order, the Gateway will redirect to the `return_url` you provided earlier. The gateway will post some data to this url. Capture them and store the necessary ones. You can pick the right order using the `reqid` they send like this :
|
28
67
|
|
68
|
+
```ruby
|
69
|
+
Order.find_by(reqid: params[:reqid])
|
70
|
+
```
|
71
|
+
|
72
|
+
Now the payment is ready to process but it's not complete and the user haven't been charged. You need to send a request to Paycorp and tell them to complete the order :
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
payment_options = {
|
76
|
+
msg_id: @order.msg_id, # Change @order as necessary
|
77
|
+
reqid: @order.reqid
|
78
|
+
}
|
79
|
+
|
80
|
+
response = PAYCORP_GATEWAY.complete_payment(payment_options)
|
81
|
+
```
|
82
|
+
|
83
|
+
Store the necessary information in the `response`. If the returned `responseCode` (`response['responseData']['responseCode']`) is `00`, the order is successful! Otherwise, there's an issue. You can find the response text in the response.
|
84
|
+
|
85
|
+
**Warning** When on testing, Paycorp will change the response code according to the amount of cents in your transaction amount. If you want to see a failing transaction, send a non 0 value as cents.
|
86
|
+
|
87
|
+
For example, if the order's amount is 100.00, the response code will be `00`. If the amount is 100.01, the response code will be `01`. This happens only during development.
|
88
|
+
|
89
|
+
## Development
|
29
90
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
91
|
|
31
92
|
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).
|
32
93
|
|
33
94
|
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/paycorp_rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
-
|
95
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/LeafyCode/paycorp_rails](https://github.com/LeafyCode/paycorp_rails). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
37
96
|
|
38
97
|
## License
|
39
|
-
|
40
98
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
99
|
|
100
|
+
## Built by
|
101
|
+
|
102
|
+
[LeafyCode.com](http://leafycode.com/)
|