payson_api 0.4.2 → 1.0.1
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 +5 -5
- data/MIT-LICENSE +16 -17
- data/README.md +228 -0
- data/lib/payson_api.rb +55 -22
- data/lib/payson_api/v1/client.rb +80 -0
- data/lib/payson_api/v1/config.rb +63 -0
- data/lib/payson_api/v1/envelope.rb +27 -0
- data/lib/payson_api/v1/errors/unknown_currency_error.rb +13 -0
- data/lib/payson_api/v1/errors/unknown_fees_payer_error.rb +13 -0
- data/lib/payson_api/v1/errors/unknown_funding_constraint_error.rb +13 -0
- data/lib/payson_api/v1/errors/unknown_guarantee_offering_error.rb +13 -0
- data/lib/payson_api/v1/errors/unknown_locale_error.rb +13 -0
- data/lib/payson_api/v1/errors/unknown_payment_action_error.rb +13 -0
- data/lib/payson_api/v1/funding.rb +38 -0
- data/lib/payson_api/v1/order_item.rb +43 -0
- data/lib/payson_api/v1/receiver.rb +46 -0
- data/lib/payson_api/v1/remote_error.rb +36 -0
- data/lib/payson_api/v1/requests/ipn.rb +19 -0
- data/lib/payson_api/v1/requests/payment.rb +68 -0
- data/lib/payson_api/v1/requests/payment_details.rb +19 -0
- data/lib/payson_api/v1/requests/payment_update.rb +27 -0
- data/lib/payson_api/v1/responses/ipn.rb +43 -0
- data/lib/payson_api/v1/responses/payment.rb +25 -0
- data/lib/payson_api/v1/responses/payment_details.rb +50 -0
- data/lib/payson_api/v1/responses/payment_update.rb +20 -0
- data/lib/payson_api/v1/responses/validate.rb +19 -0
- data/lib/payson_api/v1/sender.rb +28 -0
- data/lib/payson_api/v1/shipping_address.rb +34 -0
- data/lib/payson_api/v2/client.rb +67 -0
- data/lib/payson_api/v2/config.rb +51 -0
- data/lib/payson_api/v2/errors/unauthorized_error.rb +10 -0
- data/lib/payson_api/v2/errors/validation_error.rb +16 -0
- data/lib/payson_api/v2/models/account.rb +23 -0
- data/lib/payson_api/v2/models/checkout.rb +28 -0
- data/lib/payson_api/v2/models/customer.rb +27 -0
- data/lib/payson_api/v2/models/merchant.rb +24 -0
- data/lib/payson_api/v2/models/order.rb +32 -0
- data/lib/payson_api/v2/models/order_item.rb +33 -0
- data/lib/payson_api/v2/requests/create_checkout.rb +26 -0
- data/lib/payson_api/v2/requests/customer.rb +23 -0
- data/lib/payson_api/v2/requests/list_checkouts.rb +23 -0
- data/lib/payson_api/v2/requests/merchant.rb +25 -0
- data/lib/payson_api/v2/requests/order.rb +22 -0
- data/lib/payson_api/v2/requests/order_item.rb +27 -0
- data/lib/payson_api/v2/requests/update_checkout.rb +25 -0
- data/lib/payson_api/version.rb +3 -1
- metadata +70 -53
- data/.gitignore +0 -7
- data/.travis.yml +0 -5
- data/Gemfile +0 -2
- data/Guardfile +0 -9
- data/README.rdoc +0 -155
- data/Rakefile +0 -24
- data/lib/payson_api/client.rb +0 -79
- data/lib/payson_api/config.rb +0 -50
- data/lib/payson_api/envelope.rb +0 -21
- data/lib/payson_api/funding.rb +0 -34
- data/lib/payson_api/order_item.rb +0 -52
- data/lib/payson_api/receiver.rb +0 -52
- data/lib/payson_api/remote_error.rb +0 -31
- data/lib/payson_api/request/ipn.rb +0 -15
- data/lib/payson_api/request/payment.rb +0 -68
- data/lib/payson_api/request/payment_details.rb +0 -15
- data/lib/payson_api/request/payment_update.rb +0 -22
- data/lib/payson_api/response/ipn.rb +0 -36
- data/lib/payson_api/response/payment.rb +0 -22
- data/lib/payson_api/response/payment_details.rb +0 -43
- data/lib/payson_api/response/payment_update.rb +0 -16
- data/lib/payson_api/response/validate.rb +0 -15
- data/lib/payson_api/sender.rb +0 -29
- data/lib/payson_api/shipping_address.rb +0 -36
- data/payson_api.gemspec +0 -23
- data/test/fixtures/config.yml +0 -2
- data/test/fixtures/payment_data.yml +0 -37
- data/test/integration/config_test.rb +0 -15
- data/test/integration/payment_details_test.rb +0 -21
- data/test/integration/payment_test.rb +0 -65
- data/test/test_helper.rb +0 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 66f555c3be4e18baaad0ed1785a94c4c9b248d62aabf7cbb1caeab6c3e55ae17
|
4
|
+
data.tar.gz: 6d95db7cf0198afa8ebae7fee4d077c87b306982eb70e533f71248fa7fbbbb4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dbfff1f59b35aa89efed837854bc9b5afd3c7e6a4dceec2574715e54ceb60bd210b104803ede5f7ab8edf76999d3f037420aee9241789be178067352d37d238
|
7
|
+
data.tar.gz: cb319533f28f26526b83bffc112a5ebd6ba47ed82b16ff2724066d23032f6dea4ab00a2045ff883b15a3c34570f0bac914e27a491f56267496948c8c7445fa9e
|
data/MIT-LICENSE
CHANGED
@@ -1,20 +1,19 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2021 Christopher Svensson
|
2
2
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
the following conditions:
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
10
9
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
13
12
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
OF
|
20
|
-
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,228 @@
|
|
1
|
+
# Payson API
|
2
|
+
|
3
|
+
A simple utility to handle requests against the Payson payment gateway API.
|
4
|
+
|
5
|
+
## Supported Ruby versions
|
6
|
+
|
7
|
+
* 2.6
|
8
|
+
* 2.7
|
9
|
+
* 3.0
|
10
|
+
|
11
|
+
## Install
|
12
|
+
|
13
|
+
Put this line in your Gemfile:
|
14
|
+
|
15
|
+
gem 'payson_api'
|
16
|
+
|
17
|
+
Then bundle:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
## Usage (v2)
|
22
|
+
|
23
|
+
This explains how to use this gem with the [Payson Checkout v2 API](https://tech.payson.se/paysoncheckout2).
|
24
|
+
|
25
|
+
### General configuration options
|
26
|
+
|
27
|
+
You need to configure the gem with your own Payson credentials through the `PaysonAPI::V2.configure` method:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
PaysonAPI::V2.configure do |config|
|
31
|
+
config.api_user_id = 'XXXX'
|
32
|
+
config.api_password = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
Please note that if `config.api_user_id` is set to 4, the client will go into test mode. Valid test access credentials could be found in their [documentation](https://tech.payson.se/#Testing/sandbox).
|
37
|
+
|
38
|
+
For more detailed testing you may create your own test agent for use in the test environment. Use `config.test_mode = true`
|
39
|
+
|
40
|
+
### Showing account info
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
account = PaysonAPI::V2::Client.get_account
|
44
|
+
```
|
45
|
+
|
46
|
+
### Creating a checkout
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
request = PaysonAPI::V2::Requests::CreateCheckout.new
|
50
|
+
request.merchant.checkout_uri = 'http://localhost/checkout'
|
51
|
+
request.merchant.confirmation_uri = 'http://localhost/confirmation'
|
52
|
+
request.merchant.notification_uri = 'http://localhost/notification'
|
53
|
+
request.merchant.terms_uri = 'http://localhost/terms'
|
54
|
+
request.order.currency = 'sek'
|
55
|
+
request.order.items << PaysonAPI::V2::Requests::OrderItem.new.tap do |item|
|
56
|
+
item.name = 'My product name'
|
57
|
+
item.unit_price = 1000
|
58
|
+
item.quantity = 3
|
59
|
+
item.reference = 'product-1'
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
### Updating a checkout
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
checkout = PaysonAPI::V2::Client.get_checkout(checkout_id)
|
67
|
+
|
68
|
+
request = PaysonAPI::V2::Requests::UpdateCheckout.new
|
69
|
+
request.id = checkout.id
|
70
|
+
request.status = checkout.status
|
71
|
+
request.merchant.checkout_uri = checkout.merchant.checkout_uri
|
72
|
+
request.merchant.confirmation_uri = checkout.merchant.confirmation_uri
|
73
|
+
request.merchant.notification_uri = checkout.merchant.notification_uri
|
74
|
+
request.merchant.terms_uri = checkout.merchant.terms_uri
|
75
|
+
request.order.currency = 'eur'
|
76
|
+
request.order.items << PaysonAPI::V2::Requests::OrderItem.new.tap do |item|
|
77
|
+
item.name = 'My product name'
|
78
|
+
item.unit_price = 200
|
79
|
+
item.quantity = 3
|
80
|
+
item.reference = 'product-1'
|
81
|
+
end
|
82
|
+
request.order.items << PaysonAPI::V2::Requests::OrderItem.new.tap do |item|
|
83
|
+
item.name = 'Another product name'
|
84
|
+
item.unit_price = 600
|
85
|
+
item.quantity = 1
|
86
|
+
item.reference = 'product-2'
|
87
|
+
end
|
88
|
+
|
89
|
+
checkout = PaysonAPI::V2::Client.update_checkout(request)
|
90
|
+
```
|
91
|
+
|
92
|
+
## Usage (v1)
|
93
|
+
|
94
|
+
This explains how to use the [Payson 1.0 API](https://tech.payson.se/paysoncheckout1).
|
95
|
+
|
96
|
+
### General configuration options
|
97
|
+
|
98
|
+
You need to configure the gem with your own Payson credentials through the `PaysonAPI::V1.configure` method:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
PaysonAPI::V1.configure do |config|
|
102
|
+
config.api_user_id = 'XXXX'
|
103
|
+
config.api_password = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
Please note that if `config.api_user_id` is set to 4, the client will go into test mode. Valid test access credentials could be found in {documentation}[https://tech.payson.se/#Testing/sandbox].
|
108
|
+
|
109
|
+
For more detailed testing you may create your own test agent for use in the test environment. Use `config.test_mode = true`
|
110
|
+
|
111
|
+
### Initiating a payment
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
payment = PaysonAPI::V1::Requests::Payment.new
|
115
|
+
payment.return_url = 'http://localhost/payson/success'
|
116
|
+
payment.cancel_url = 'http://localhost/payson/cancel'
|
117
|
+
payment.ipn_url = 'http://localhost/payson/ipn'
|
118
|
+
payment.memo = 'Sample order description'
|
119
|
+
payment.sender = sender
|
120
|
+
|
121
|
+
payment.sender = PaysonAPI::V1::Sender.new.tap do |s|
|
122
|
+
s.email = 'mycustomer@mydomain.com'
|
123
|
+
s.first_name = 'My'
|
124
|
+
s.last_name = 'Customer'
|
125
|
+
end
|
126
|
+
|
127
|
+
payment.receivers = []
|
128
|
+
payment.receivers << PaysonAPI::V1::Receiver.new.tap do |r|
|
129
|
+
r.email = 'me@mydomain.com'
|
130
|
+
r.amount = 100
|
131
|
+
r.first_name = 'Me'
|
132
|
+
r.last_name = 'Just me'
|
133
|
+
r.primary = true
|
134
|
+
end
|
135
|
+
|
136
|
+
payment.order_items = []
|
137
|
+
payment.order_items << PaysonAPI::V1::OrderItem.new.tap do |i|
|
138
|
+
i.description = 'Order item description'
|
139
|
+
i.unit_price = 100
|
140
|
+
i.quantity = 1
|
141
|
+
i.tax = 0
|
142
|
+
i.sku = 'MY-ITEM-1'
|
143
|
+
end
|
144
|
+
|
145
|
+
response = PaysonAPI::V1::Client.initiate_payment(payment)
|
146
|
+
|
147
|
+
if response.success?
|
148
|
+
# Redirect to response.forward_url
|
149
|
+
else
|
150
|
+
puts response.errors
|
151
|
+
end
|
152
|
+
```
|
153
|
+
|
154
|
+
### Requesting payment details
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
token = 'token-received-from-payment-request'
|
158
|
+
|
159
|
+
payment_details = PaysonAPI::V1::Requests::PaymentDetails.new(token)
|
160
|
+
|
161
|
+
response = PaysonAPI::V1::Client.get_payment_details(payment_details)
|
162
|
+
|
163
|
+
if response.success?
|
164
|
+
# Do stuff with response object
|
165
|
+
else
|
166
|
+
puts response.errors
|
167
|
+
end
|
168
|
+
```
|
169
|
+
|
170
|
+
### Updating a payment
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
token = 'token-received-from-payment-request'
|
174
|
+
action = 'CANCELORDER'
|
175
|
+
|
176
|
+
payment_update = PaysonAPI::V1::Requests::PaymentUpdate.new(token, action)
|
177
|
+
|
178
|
+
response = PaysonAPI::V1::Client.update_payment(payment_update)
|
179
|
+
|
180
|
+
if response.success?
|
181
|
+
# Do stuff with response object
|
182
|
+
else
|
183
|
+
puts response.errors
|
184
|
+
end
|
185
|
+
```
|
186
|
+
|
187
|
+
### Validating an IPN response
|
188
|
+
|
189
|
+
This example assumes the use of the Rails web framework.
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
class Payson < ApplicationController
|
193
|
+
def ipn_responder
|
194
|
+
request_body = request.body.read
|
195
|
+
ipn_response = PaysonAPI::V1::Responses::IPN.new(request_body)
|
196
|
+
|
197
|
+
# Create a new IPN request object containing the raw response from above
|
198
|
+
ipn_request = PaysonAPI::V1::Requests::IPN.new(ipn_response.raw)
|
199
|
+
|
200
|
+
validate = PaysonAPI::V1::Client.validate_ipn(ipn_request)
|
201
|
+
|
202
|
+
unless validate.verified?
|
203
|
+
raise "Something went terribly wrong."
|
204
|
+
end
|
205
|
+
|
206
|
+
# Do business transactions, e.g. update the corresponding order:
|
207
|
+
# order = Order.find_by_payson_token(ipn_response.token)
|
208
|
+
# order.payson_status = ipn_response.status
|
209
|
+
# order.save!
|
210
|
+
end
|
211
|
+
end
|
212
|
+
```
|
213
|
+
|
214
|
+
## Todo
|
215
|
+
|
216
|
+
Document the code for the Payson Checkout v2 processes.
|
217
|
+
|
218
|
+
## Build Status
|
219
|
+
|
220
|
+
[](https://travis-ci.org/stoffus/payson_api)
|
221
|
+
|
222
|
+
## Questions, Feedback
|
223
|
+
|
224
|
+
Feel free to message me on Github (stoffus).
|
225
|
+
|
226
|
+
## Copyright
|
227
|
+
|
228
|
+
Copyright (c) 2021 Christopher Svensson.
|
data/lib/payson_api.rb
CHANGED
@@ -1,25 +1,58 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'payson_api/version'
|
4
|
+
|
5
|
+
required_files_v1 = %w[
|
6
|
+
config
|
7
|
+
client
|
8
|
+
envelope
|
9
|
+
errors/unknown_currency_error
|
10
|
+
errors/unknown_fees_payer_error
|
11
|
+
errors/unknown_funding_constraint_error
|
12
|
+
errors/unknown_guarantee_offering_error
|
13
|
+
errors/unknown_locale_error
|
14
|
+
errors/unknown_payment_action_error
|
15
|
+
funding
|
16
|
+
order_item
|
17
|
+
receiver
|
18
|
+
remote_error
|
19
|
+
requests/ipn
|
20
|
+
requests/payment_details
|
21
|
+
requests/payment_update
|
22
|
+
requests/payment
|
23
|
+
responses/ipn
|
24
|
+
responses/payment_details
|
25
|
+
responses/payment_update
|
26
|
+
responses/payment
|
27
|
+
responses/validate
|
28
|
+
sender
|
29
|
+
shipping_address
|
30
|
+
]
|
31
|
+
|
32
|
+
required_files_v2 = %w[
|
33
|
+
config
|
34
|
+
client
|
35
|
+
errors/validation_error
|
36
|
+
errors/unauthorized_error
|
37
|
+
models/account
|
38
|
+
models/checkout
|
39
|
+
models/customer
|
40
|
+
models/merchant
|
41
|
+
models/order_item
|
42
|
+
models/order
|
43
|
+
requests/order_item
|
44
|
+
requests/customer
|
45
|
+
requests/merchant
|
46
|
+
requests/order
|
47
|
+
requests/create_checkout
|
48
|
+
requests/update_checkout
|
49
|
+
requests/list_checkouts
|
21
50
|
]
|
22
51
|
|
23
|
-
|
24
|
-
|
52
|
+
required_files_v1.each do |file|
|
53
|
+
require_relative "payson_api/v1/#{file}"
|
54
|
+
end
|
55
|
+
|
56
|
+
required_files_v2.each do |file|
|
57
|
+
require_relative "payson_api/v2/#{file}"
|
25
58
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/https'
|
4
|
+
|
5
|
+
module PaysonAPI
|
6
|
+
module V1
|
7
|
+
class Client
|
8
|
+
def self.initiate_payment(payment_data)
|
9
|
+
response = payson_request(
|
10
|
+
PAYSON_API_PAY_ACTION,
|
11
|
+
payment_data.to_hash
|
12
|
+
)
|
13
|
+
response_hash = params_to_hash(response.body)
|
14
|
+
PaysonAPI::V1::Responses::Payment.new(response_hash)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_payment_details(payment_details_data)
|
18
|
+
response = payson_request(
|
19
|
+
PAYSON_API_PAYMENT_DETAILS_ACTION,
|
20
|
+
payment_details_data.to_hash
|
21
|
+
)
|
22
|
+
response_hash = params_to_hash(response.body)
|
23
|
+
PaysonAPI::V1::Responses::PaymentDetails.new(response_hash)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.update_payment(payment_update_data)
|
27
|
+
response = payson_request(
|
28
|
+
PAYSON_API_PAYMENT_DETAILS_ACTION,
|
29
|
+
payment_update_data.to_hash
|
30
|
+
)
|
31
|
+
response_hash = params_to_hash(response.body)
|
32
|
+
PaysonAPI::V1::Responses::PaymentUpdate.new(response_hash)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.validate_ipn(ipn_data)
|
36
|
+
response = payson_request(
|
37
|
+
PAYSON_API_PAYMENT_VALIDATE_ACTION,
|
38
|
+
ipn_data.to_s
|
39
|
+
)
|
40
|
+
PaysonAPI::V1::Responses::Validate.new(response.body)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.hash_to_params(hash)
|
44
|
+
hash.map { |k, v| "#{k}=#{URI.encode_www_form_component(v.to_s)}" }.join('&')
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.params_to_hash(params)
|
48
|
+
{}.tap do |hash|
|
49
|
+
params.split('&').each do |param|
|
50
|
+
key, val = param.split('=')
|
51
|
+
hash[key] = URI.decode_www_form_component(val)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.payson_request(action, data)
|
57
|
+
path = format('/%<api_version>s/%<action>s/', api_version: PAYSON_API_VERSION, action: action)
|
58
|
+
url = PaysonAPI::V1.api_base_url + path
|
59
|
+
headers = {
|
60
|
+
'PAYSON-SECURITY-USERID' => PaysonAPI::V1.config.api_user_id,
|
61
|
+
'PAYSON-SECURITY-PASSWORD' => PaysonAPI::V1.config.api_password,
|
62
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
63
|
+
}
|
64
|
+
post(url, data, headers)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.post(url, data, headers)
|
68
|
+
uri = URI.parse(url)
|
69
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
70
|
+
http.use_ssl = uri.scheme == 'https'
|
71
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
72
|
+
req.body = data.is_a?(Hash) ? hash_to_params(data) : data
|
73
|
+
headers.each do |name, value|
|
74
|
+
req[name] = value
|
75
|
+
end
|
76
|
+
http.request(req)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaysonAPI
|
4
|
+
module V1
|
5
|
+
module_function
|
6
|
+
|
7
|
+
PAYSON_WWW_HOST_ENDPOINT = 'https://www.payson.se'
|
8
|
+
PAYSON_WWW_PAY_FORWARD_URL = '/paysecure/?token=%s'
|
9
|
+
|
10
|
+
PAYSON_API_ENDPOINT = 'https://api.payson.se'
|
11
|
+
PAYSON_API_VERSION = '1.0'
|
12
|
+
PAYSON_API_PAY_ACTION = 'Pay'
|
13
|
+
PAYSON_API_PAYMENT_DETAILS_ACTION = 'PaymentDetails'
|
14
|
+
PAYSON_API_PAYMENT_UPDATE_ACTION = 'PaymentUpdate'
|
15
|
+
PAYSON_API_PAYMENT_VALIDATE_ACTION = 'Validate'
|
16
|
+
|
17
|
+
PAYSON_API_TEST_ENDPOINT = 'https://test-api.payson.se'
|
18
|
+
PAYSON_WWW_HOST_TEST_ENDPOINT = 'https://test-www.payson.se'
|
19
|
+
|
20
|
+
LOCALES = %w[SV EN FI].freeze
|
21
|
+
CURRENCIES = %w[SEK EUR].freeze
|
22
|
+
FEES_PAYERS = %w[EACHRECEIVER SENDER PRIMARYRECEIVER SECONDARYONLY].freeze
|
23
|
+
FUNDING_CONSTRAINTS = %w[CREDITCARD BANK INVOICE SMS].freeze
|
24
|
+
GUARANTEE_OFFERINGS = %w[OPTIONAL REQUIRED NO].freeze
|
25
|
+
PAYMENT_STATUSES = %w[CREATED PENDING PROCESSING COMPLETED CREDITED
|
26
|
+
INCOMPLETE ERROR EXPIRED REVERSALERROR ABORTED].freeze
|
27
|
+
PAYMENT_TYPES = %w[TRANSFER GUARANTEE INVOICE].freeze
|
28
|
+
GUARANTEE_STATUSES = %w[WAITINGFORSEND WAITINGFORACCEPTANCE WAITINGFORRETURN
|
29
|
+
WAITINGFORRETURNACCEPTANCE RETURNNOTACCEPTED NOTRECEIVED RETURNNOTRECEIVED
|
30
|
+
MONEYRETURNEDTOSENDER RETURNACCEPTED].freeze
|
31
|
+
INVOICE_STATUSES = %w[PENDING ORDERCREATED CANCELED SHIPPED DONE CREDITED].freeze
|
32
|
+
PAYMENT_ACTIONS = %w[CANCELORDER SHIPORDER CREDITORDER REFUND].freeze
|
33
|
+
|
34
|
+
def configure
|
35
|
+
yield @config ||= Configuration.new # rubocop:disable Naming/MemoizedInstanceVariableName
|
36
|
+
end
|
37
|
+
|
38
|
+
def config
|
39
|
+
@config
|
40
|
+
end
|
41
|
+
|
42
|
+
class Configuration
|
43
|
+
attr_accessor :api_user_id, :api_password, :test_mode
|
44
|
+
end
|
45
|
+
|
46
|
+
configure do |config|
|
47
|
+
config.api_user_id = 'XXXX'
|
48
|
+
config.api_password = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
|
49
|
+
end
|
50
|
+
|
51
|
+
def test?
|
52
|
+
@config.test_mode || @config.api_user_id == '4'
|
53
|
+
end
|
54
|
+
|
55
|
+
def api_base_url
|
56
|
+
test? ? PAYSON_API_TEST_ENDPOINT : PAYSON_API_ENDPOINT
|
57
|
+
end
|
58
|
+
|
59
|
+
def forward_url(token)
|
60
|
+
(test? ? PAYSON_WWW_HOST_TEST_ENDPOINT : PAYSON_WWW_HOST_ENDPOINT) + PAYSON_WWW_PAY_FORWARD_URL % token
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|