smartpay 0.2.3 → 0.2.4
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 +68 -3
- data/lib/generators/smartpay/templates/initializer.rb +2 -2
- data/lib/smartpay/configuration.rb +1 -1
- data/lib/smartpay/responses/checkout_session.rb +11 -3
- data/lib/smartpay/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: 6c3f54543398cb0fc174621f0527f86329337fb0bce18911f334b32389358db6
|
4
|
+
data.tar.gz: fd7f015bfa49ec0bdf491e34113048098cae02c782abf3b1a8e8bf2df1799387
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72b70c530d31746bc173e6544dec2681413c97f9ebb099afed726366400e2f5a3420bcc44e078ece36debfd8fd858aec05c77f346c994605eb7900e468774d25
|
7
|
+
data.tar.gz: ff85cd4be5986f315734e67d312b9f0696c7702ca11cb4a4d6768808c26a4557d23f01851f37fbd9506e178399a02224aacceee7e9e32719f2629cbceb95a109
|
data/README.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
The Smartpay Ruby library offers easy access to Smartpay API from applications written in Ruby.
|
4
4
|
|
5
|
+
## Documentation
|
6
|
+
|
7
|
+
- [Payment Flow](https://docs.smartpay.co/#payment_flow)
|
8
|
+
- [API Document](https://api-doc.smartpay.co)
|
9
|
+
|
5
10
|
## Requirements
|
6
11
|
|
7
12
|
- Ruby 2.6+
|
@@ -33,6 +38,66 @@ source 'https://rubygems.org'
|
|
33
38
|
gem 'smartpay'
|
34
39
|
```
|
35
40
|
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
The package needs to be configured with your own API keys, you can find them on your [dashboard](https://dashboard.smartpay.co/settings/credentials).
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
Smartpay.configure do |config|
|
47
|
+
config.public_key = '<YOUR_PUBLIC_KEY>' # the one starts with pk_test_
|
48
|
+
config.secret_key = '<YOUR_SECRET_KEY>' # the one starts with sk_test_
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
### Create Checkout session
|
53
|
+
|
54
|
+
You can find the description and requirement for request payload in [API Document](https://api-doc.smartpay.co/#8a3538b1-530c-448c-8bae-4a41cdf0b8fd).
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
payloaad = {
|
58
|
+
"customerInfo": {
|
59
|
+
"emailAddress": "success@smartpay.co",
|
60
|
+
},
|
61
|
+
"orderData": {
|
62
|
+
"amount": 250,
|
63
|
+
"currency": "JPY",
|
64
|
+
"shippingInfo": {
|
65
|
+
"address": {
|
66
|
+
"line1": "line1",
|
67
|
+
"locality": "locality",
|
68
|
+
"postalCode": "123",
|
69
|
+
"country": "JP"
|
70
|
+
},
|
71
|
+
},
|
72
|
+
"lineItemData": [{
|
73
|
+
"priceData": {
|
74
|
+
"productData": {
|
75
|
+
"name": "レブロン 18 LOW",
|
76
|
+
},
|
77
|
+
"amount": 250,
|
78
|
+
"currency": "JPY",
|
79
|
+
},
|
80
|
+
"quantity": 1
|
81
|
+
}]
|
82
|
+
},
|
83
|
+
"reference": "order_ref_1234567",
|
84
|
+
"successUrl": "https://docs.smartpay.co/example-pages/checkout-successful",
|
85
|
+
"cancelUrl": "https://docs.smartpay.co/example-pages/checkout-canceled"
|
86
|
+
}
|
87
|
+
```
|
88
|
+
|
89
|
+
Create a checkout session by using `Smartpay::Api.create_checkout_session` with your request payload.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
session = Smartpay::Api.create_checkout_session(payload)
|
93
|
+
```
|
94
|
+
|
95
|
+
Then, you can redirect your customer to the session url by calling `redirect_url`:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
session.redirect_url
|
99
|
+
```
|
100
|
+
|
36
101
|
## Use with your favorite frameworks
|
37
102
|
|
38
103
|
### Ruby on Rails (RoR)
|
@@ -64,7 +129,7 @@ bundle exec rails generate smartpay:install
|
|
64
129
|
|
65
130
|
This introduces 4 changes for a pre-built Smartpay Checkout example:
|
66
131
|
|
67
|
-
> 1. A new initializer - `config/initializers/smartpay.rb`. You will have to update the `config.
|
132
|
+
> 1. A new initializer - `config/initializers/smartpay.rb`. You will have to update the `config.public_key` and `config.secret_key` with your own credentials to make this work.
|
68
133
|
> 2. A new controller - `app/controllers/smartpays_controller.rb`. This is where you can see how a Checkout session is configured & created.
|
69
134
|
> 3. A new view - `app/views/smartpays/index.html.erb`. The minimum frontend required.
|
70
135
|
> 4. A new route in config/routes.rb.
|
@@ -75,8 +140,8 @@ Edit the keys with your own credentials in `config/initializers/smartpay.rb`.
|
|
75
140
|
|
76
141
|
```ruby
|
77
142
|
...
|
78
|
-
config.
|
79
|
-
config.
|
143
|
+
config.public_key = '<YOUR_PUBLIC_KEY>' # the one starts with pk_test_
|
144
|
+
config.secret_key = '<YOUR_SECRET_KEY>' # the one starts with sk_test_
|
80
145
|
...
|
81
146
|
```
|
82
147
|
|
@@ -3,6 +3,6 @@
|
|
3
3
|
Smartpay.configure do |config|
|
4
4
|
config.api_url = 'https://api.smartpay.co/smartpayments'
|
5
5
|
config.checkout_url = 'https://checkout.smartpay.co'
|
6
|
-
config.
|
7
|
-
config.
|
6
|
+
config.public_key = 'pk_test_'
|
7
|
+
config.secret_key = 'sk_test_'
|
8
8
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Smartpay
|
4
4
|
class Configuration
|
5
5
|
attr_accessor :post_timeout
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :public_key, :secret_key, :api_url, :checkout_url
|
7
7
|
|
8
8
|
DEFAULT_TIMEOUT_SETTING = 30
|
9
9
|
DEFAULT_API_URL = 'https://api.smartpay.co'
|
@@ -10,7 +10,15 @@ module Smartpay
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def redirect_url
|
13
|
-
URI.escape("#{checkout_url}/login?session-id=#{response[:id]}&public-key=#{
|
13
|
+
URI.escape("#{checkout_url}/login?session-id=#{response[:id]}&public-key=#{public_key}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def as_hash
|
17
|
+
@response
|
18
|
+
end
|
19
|
+
|
20
|
+
def as_json
|
21
|
+
@response.to_json
|
14
22
|
end
|
15
23
|
|
16
24
|
private
|
@@ -19,8 +27,8 @@ module Smartpay
|
|
19
27
|
Smartpay.configuration.checkout_url
|
20
28
|
end
|
21
29
|
|
22
|
-
def
|
23
|
-
Smartpay.configuration.
|
30
|
+
def public_key
|
31
|
+
Smartpay.configuration.public_key
|
24
32
|
end
|
25
33
|
end
|
26
34
|
end
|
data/lib/smartpay/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartpay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Smartpay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|