payson_api 1.0.1 → 1.0.2
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 +13 -11
- data/lib/payson_api/v2/client.rb +5 -3
- data/lib/payson_api/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: 4542d9a26a029687326f4a3f7f8fbc196b1c7f1c1c176407aea8f45cf1621346
|
4
|
+
data.tar.gz: 2d0b654fea59184a93827c87e6f57dde0d6194ae8dd81b3d6e7e541415349f6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 741d52cce371302839ce8ff2f68dd4b92c9312724563c22091fed701f5f06f3110ce0596464df6982121d5eaa1daac50ed71e6a4c8b1e0907275ee5a10558746
|
7
|
+
data.tar.gz: ce5ff56b813dbdb555845072de35b872328613ebddc1e5c84204b6999a96cff20c154aa368f53bc464123370c7dcdab61a891c736f94ebd0dfa8bcf88c4578ba
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Payson API
|
2
2
|
|
3
|
-
A
|
3
|
+
A zero dependency, pure Ruby utility to handle requests against the Payson payment gateway API.
|
4
4
|
|
5
5
|
## Supported Ruby versions
|
6
6
|
|
@@ -8,7 +8,7 @@ A simple utility to handle requests against the Payson payment gateway API.
|
|
8
8
|
* 2.7
|
9
9
|
* 3.0
|
10
10
|
|
11
|
-
##
|
11
|
+
## Installation
|
12
12
|
|
13
13
|
Put this line in your Gemfile:
|
14
14
|
|
@@ -58,6 +58,10 @@ request.order.items << PaysonAPI::V2::Requests::OrderItem.new.tap do |item|
|
|
58
58
|
item.quantity = 3
|
59
59
|
item.reference = 'product-1'
|
60
60
|
end
|
61
|
+
|
62
|
+
checkout = PaysonAPI::V2::Client.create_checkout(request)
|
63
|
+
|
64
|
+
# Continue by rendering the HTML from checkout.snippet.
|
61
65
|
```
|
62
66
|
|
63
67
|
### Updating a checkout
|
@@ -116,8 +120,6 @@ payment.return_url = 'http://localhost/payson/success'
|
|
116
120
|
payment.cancel_url = 'http://localhost/payson/cancel'
|
117
121
|
payment.ipn_url = 'http://localhost/payson/ipn'
|
118
122
|
payment.memo = 'Sample order description'
|
119
|
-
payment.sender = sender
|
120
|
-
|
121
123
|
payment.sender = PaysonAPI::V1::Sender.new.tap do |s|
|
122
124
|
s.email = 'mycustomer@mydomain.com'
|
123
125
|
s.first_name = 'My'
|
@@ -197,10 +199,10 @@ class Payson < ApplicationController
|
|
197
199
|
# Create a new IPN request object containing the raw response from above
|
198
200
|
ipn_request = PaysonAPI::V1::Requests::IPN.new(ipn_response.raw)
|
199
201
|
|
200
|
-
|
202
|
+
validation = PaysonAPI::V1::Client.validate_ipn(ipn_request)
|
201
203
|
|
202
|
-
unless
|
203
|
-
raise "Something went terribly wrong
|
204
|
+
unless validation.verified?
|
205
|
+
raise "Something went terribly wrong"
|
204
206
|
end
|
205
207
|
|
206
208
|
# Do business transactions, e.g. update the corresponding order:
|
@@ -213,15 +215,15 @@ end
|
|
213
215
|
|
214
216
|
## Todo
|
215
217
|
|
216
|
-
|
218
|
+
Nothing at the moment.
|
217
219
|
|
218
|
-
##
|
220
|
+
## Project Status
|
219
221
|
|
220
|
-
[](https://travis-ci.org/stoffus/payson_api)
|
222
|
+
[](https://travis-ci.org/stoffus/payson_api) [](https://badge.fury.io/rb/payson_api)
|
221
223
|
|
222
224
|
## Questions, Feedback
|
223
225
|
|
224
|
-
Feel free to message me on
|
226
|
+
Feel free to message me on [GitHub](https://github.com/stoffus).
|
225
227
|
|
226
228
|
## Copyright
|
227
229
|
|
data/lib/payson_api/v2/client.rb
CHANGED
@@ -18,13 +18,13 @@ module PaysonAPI
|
|
18
18
|
|
19
19
|
def self.create_checkout(request)
|
20
20
|
response = payson_request(Net::HTTP::Post, PAYSON_API_RESOURCES[:checkouts][:create], request)
|
21
|
-
|
21
|
+
intercept_validation_errors(response)
|
22
22
|
PaysonAPI::V2::Models::Checkout.from_hash(JSON.parse(response.body))
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.update_checkout(request)
|
26
26
|
response = payson_request(Net::HTTP::Put, PAYSON_API_RESOURCES[:checkouts][:update] % request.id, request)
|
27
|
-
|
27
|
+
intercept_validation_errors(response)
|
28
28
|
PaysonAPI::V2::Models::Checkout.from_hash(JSON.parse(response.body))
|
29
29
|
end
|
30
30
|
|
@@ -38,7 +38,7 @@ module PaysonAPI
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
def self.
|
41
|
+
def self.intercept_validation_errors(response)
|
42
42
|
if response.code == '400' || response.code == '500' # rubocop:disable Style/GuardClause
|
43
43
|
raise PaysonAPI::V2::Errors::ValidationError, errors: JSON.parse(response.body)['errors']
|
44
44
|
end
|
@@ -62,6 +62,8 @@ module PaysonAPI
|
|
62
62
|
|
63
63
|
response
|
64
64
|
end
|
65
|
+
|
66
|
+
private_class_method :intercept_validation_errors, :hash_to_params, :payson_request
|
65
67
|
end
|
66
68
|
end
|
67
69
|
end
|
data/lib/payson_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: payson_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Svensson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|