smartpay 0.2.0 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +137 -27
- data/lib/generators/smartpay/install_generator.rb +1 -0
- data/lib/generators/smartpay/templates/assets/stylesheets/demo.css +18 -0
- data/lib/generators/smartpay/templates/initializer.rb +3 -3
- data/lib/generators/smartpay/templates/views/index.html.erb +3 -0
- data/lib/smartpay/client.rb +3 -3
- data/lib/smartpay/configuration.rb +1 -1
- data/lib/smartpay/responses/checkout_session.rb +8 -0
- data/lib/smartpay/version.rb +1 -1
- metadata +3 -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
@@ -1,56 +1,166 @@
|
|
1
|
-
# Smartpay
|
1
|
+
# Smartpay Ruby Library
|
2
2
|
|
3
|
-
|
3
|
+
The Smartpay Ruby library offers easy access to Smartpay API from applications written in Ruby.
|
4
4
|
|
5
|
-
|
5
|
+
## Documentation
|
6
|
+
|
7
|
+
- [Payment Flow](https://docs.smartpay.co/#payment_flow)
|
8
|
+
- [API Document](https://api-doc.smartpay.co)
|
9
|
+
|
10
|
+
## Requirements
|
11
|
+
|
12
|
+
- Ruby 2.6+
|
13
|
+
- Smartpay `API keys & secrets`. You can find your credential at the `settings > credentials` page on your [dashboard](https://dashboard.smartpay.co/settings/credentials).
|
6
14
|
|
7
15
|
## Installation
|
8
16
|
|
9
|
-
|
17
|
+
If you use system built-in Ruby, you might need to be the `sudoer` to be able to `sudo` in some of the following steps. We recommend you to use either [rbenv](https://github.com/rbenv/rbenv) or [rvm](https://rvm.io/) to have your own non-global Ruby to avoid potential permission issues.
|
18
|
+
|
19
|
+
Once you have your Ruby in place, add the latest version of Smartpay to your project's dependencies:
|
20
|
+
|
21
|
+
```sh
|
22
|
+
gem install smartpay
|
23
|
+
```
|
24
|
+
|
25
|
+
If you want to build the gem yourself from source:
|
26
|
+
|
27
|
+
```sh
|
28
|
+
gem build smartpay.gemspec
|
29
|
+
```
|
30
|
+
|
31
|
+
### Bundler
|
32
|
+
|
33
|
+
If you are installing via bundler, make sure that you use the `https` resource in your Gemfile to avoid the risk of gems being compromised:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
source 'https://rubygems.org'
|
37
|
+
|
38
|
+
gem 'smartpay'
|
39
|
+
```
|
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
|
10
53
|
|
11
|
-
|
54
|
+
You can find the description and requirement for request payload in [API Document](https://api-doc.smartpay.co/#8a3538b1-530c-448c-8bae-4a41cdf0b8fd).
|
12
55
|
|
13
|
-
|
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.
|
14
90
|
|
15
91
|
```ruby
|
16
|
-
|
92
|
+
session = Smartpay::Api.create_checkout_session(payload)
|
17
93
|
```
|
18
94
|
|
19
|
-
|
95
|
+
Then, you can redirect your customer to the session url by calling `redirect_url`:
|
20
96
|
|
21
|
-
|
97
|
+
```ruby
|
98
|
+
session.redirect_url
|
99
|
+
```
|
22
100
|
|
23
|
-
##
|
101
|
+
## Use with your favorite frameworks
|
24
102
|
|
25
|
-
|
103
|
+
### Ruby on Rails (RoR)
|
26
104
|
|
27
|
-
|
105
|
+
#### Install Rails
|
28
106
|
|
29
|
-
|
107
|
+
```sh
|
108
|
+
gem install rails
|
109
|
+
```
|
30
110
|
|
31
|
-
|
32
|
-
2. Add controller to `app/controllers/smartpays_controller.rb`
|
33
|
-
3. Add view to `app/views/smartpays/index.html.erb`
|
34
|
-
4. Add routes to `config/routes.rb` for checkout session
|
111
|
+
#### Create your app
|
35
112
|
|
36
|
-
|
113
|
+
```sh
|
114
|
+
rails new app-with-smartpay
|
115
|
+
```
|
116
|
+
|
117
|
+
#### Add Smartpay
|
37
118
|
|
38
|
-
|
39
|
-
|
119
|
+
```sh
|
120
|
+
cd app-with-smartpay
|
121
|
+
bundle add smartpay
|
122
|
+
```
|
40
123
|
|
41
|
-
|
124
|
+
#### Generator
|
125
|
+
|
126
|
+
```sh
|
127
|
+
bundle exec rails generate smartpay:install
|
128
|
+
```
|
129
|
+
|
130
|
+
This introduces 4 changes for a pre-built Smartpay Checkout example:
|
131
|
+
|
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.
|
133
|
+
> 2. A new controller - `app/controllers/smartpays_controller.rb`. This is where you can see how a Checkout session is configured & created.
|
134
|
+
> 3. A new view - `app/views/smartpays/index.html.erb`. The minimum frontend required.
|
135
|
+
> 4. A new route in config/routes.rb.
|
136
|
+
|
137
|
+
#### Fill in your API keys
|
138
|
+
|
139
|
+
Edit the keys with your own credentials in `config/initializers/smartpay.rb`.
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
...
|
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_
|
145
|
+
...
|
146
|
+
```
|
147
|
+
|
148
|
+
#### Start your server
|
149
|
+
|
150
|
+
```sh
|
151
|
+
bundle exec rails server
|
152
|
+
```
|
42
153
|
|
43
154
|
### Test with Checkout Session
|
44
155
|
|
45
|
-
|
156
|
+
Visit [http://localhost:3000/smartpays](http://localhost:3000/smartpays).
|
46
157
|
|
47
|
-
Click the `checkout` button to be redirected to
|
158
|
+
Click the `checkout` button on the page to be redirected to Smartpay's Checkout.
|
48
159
|
|
49
|
-
|
160
|
+
To try out different cases, you can use the following test credit cards for different cases:
|
50
161
|
|
51
|
-
|
52
|
-
|
53
|
-
3. Payment is declined: `declined@smartpay.co`
|
162
|
+
- Payment succeeds: `4242 4242 4242 4242`
|
163
|
+
- Payment is declined: `4100 0000 0000 0019`
|
54
164
|
|
55
165
|
## Development
|
56
166
|
|
@@ -9,6 +9,7 @@ module Smartpay
|
|
9
9
|
def install
|
10
10
|
template "initializer.rb", "config/initializers/smartpay.rb"
|
11
11
|
template "controller.rb", "app/controllers/smartpays_controller.rb"
|
12
|
+
template "assets/stylesheets/demo.css", "app/assets/stylesheets/demo.css"
|
12
13
|
directory "views", "app/views/smartpays"
|
13
14
|
|
14
15
|
route "resources :smartpays, only: [:index, :create]"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
input[type="submit"] {
|
2
|
+
padding: 0 40px;
|
3
|
+
font: 500 16px/48px Helvetica, sans-serif;
|
4
|
+
appearance: none;
|
5
|
+
position: absolute;
|
6
|
+
left: 50%;
|
7
|
+
top: 50%;
|
8
|
+
transform: translate(-50%, -50%);
|
9
|
+
border: 0;
|
10
|
+
color: #fff;
|
11
|
+
background: #4456dd;
|
12
|
+
border-radius: 6px;
|
13
|
+
cursor: pointer;
|
14
|
+
}
|
15
|
+
|
16
|
+
input[type="submit"]:hover {
|
17
|
+
background: #3445c1;
|
18
|
+
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Smartpay.configure do |config|
|
4
|
-
config.api_url = 'https://api.smartpay.
|
5
|
-
config.checkout_url = 'https://checkout.smartpay.
|
4
|
+
config.api_url = 'https://api.smartpay.co/smartpayments'
|
5
|
+
config.checkout_url = 'https://checkout.smartpay.co'
|
6
6
|
config.public_key = 'pk_test_'
|
7
|
-
config.
|
7
|
+
config.secret_key = 'sk_test_'
|
8
8
|
end
|
data/lib/smartpay/client.rb
CHANGED
@@ -24,12 +24,12 @@ module Smartpay
|
|
24
24
|
{
|
25
25
|
accept: :json,
|
26
26
|
content_type: :json,
|
27
|
-
Authorization: "Basic #{
|
27
|
+
Authorization: "Basic #{private_api_key}"
|
28
28
|
}
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
Smartpay.configuration.
|
31
|
+
def private_api_key
|
32
|
+
Smartpay.configuration.private_api_key
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Smartpay
|
4
4
|
class Configuration
|
5
5
|
attr_accessor :post_timeout
|
6
|
-
attr_accessor :public_key, :
|
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'
|
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
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- bin/console
|
57
57
|
- bin/setup
|
58
58
|
- lib/generators/smartpay/install_generator.rb
|
59
|
+
- lib/generators/smartpay/templates/assets/stylesheets/demo.css
|
59
60
|
- lib/generators/smartpay/templates/controller.rb
|
60
61
|
- lib/generators/smartpay/templates/initializer.rb
|
61
62
|
- lib/generators/smartpay/templates/views/index.html.erb
|