smartpay 0.0.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +83 -10
- data/lib/generators/smartpay/install_generator.rb +18 -0
- data/lib/generators/smartpay/templates/assets/stylesheets/demo.css +18 -0
- data/lib/generators/smartpay/templates/controller.rb +68 -0
- data/lib/generators/smartpay/templates/initializer.rb +8 -0
- data/lib/generators/smartpay/templates/views/index.html.erb +11 -0
- data/lib/smartpay/api.rb +11 -0
- data/lib/smartpay/client.rb +36 -0
- data/lib/smartpay/configuration.rb +18 -0
- data/lib/smartpay/responses/checkout_session.rb +27 -0
- data/lib/smartpay/version.rb +1 -1
- data/lib/smartpay.rb +17 -2
- metadata +42 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86faee4c994b67bdf3ff9d2454a85d09577b82475917e5048fdb3c373ba1fe30
|
4
|
+
data.tar.gz: 64babfa347d6f484ec3aea689bf735a3aa294e182c95cf80840fcc0632dca043
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d4e5f3a352166fff345a6e6cc3b6e68125b74dae5d0913fc78e780aa37dbe754eb18274ceab76152a991dfd82a883b7d49f8ce93d0a26294d83590f9cb1deb1
|
7
|
+
data.tar.gz: b18f1f1c5602dca17d548e29f525b9238e9490b0340ed6dc69c8b29e8b22c3e300cecad3a6e658ecf31b333d2c0c2dca660bc1ffd2190d7d55a54e500c99c575
|
data/README.md
CHANGED
@@ -1,28 +1,101 @@
|
|
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
|
+
## Requirements
|
6
|
+
|
7
|
+
- Ruby 2.6+
|
8
|
+
- Smartpay `API keys & secrets`. You can find your credential at the `settings > credentials` page on your [dashboard](https://dashboard.smartpay.co/settings/credentials).
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
9
|
-
|
12
|
+
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.
|
13
|
+
|
14
|
+
Once you have your Ruby in place, add the latest version of Smartpay to your project's dependencies:
|
15
|
+
|
16
|
+
```sh
|
17
|
+
gem install smartpay
|
18
|
+
```
|
19
|
+
|
20
|
+
If you want to build the gem yourself from source:
|
21
|
+
|
22
|
+
```sh
|
23
|
+
gem build smartpay.gemspec
|
24
|
+
```
|
25
|
+
|
26
|
+
### Bundler
|
27
|
+
|
28
|
+
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:
|
10
29
|
|
11
30
|
```ruby
|
31
|
+
source 'https://rubygems.org'
|
32
|
+
|
12
33
|
gem 'smartpay'
|
13
34
|
```
|
14
35
|
|
15
|
-
|
36
|
+
## Use with your favorite frameworks
|
37
|
+
|
38
|
+
### Ruby on Rails (RoR)
|
39
|
+
|
40
|
+
#### Install Rails
|
41
|
+
|
42
|
+
```sh
|
43
|
+
gem install rails
|
44
|
+
```
|
45
|
+
|
46
|
+
#### Create your app
|
47
|
+
|
48
|
+
```sh
|
49
|
+
rails new app-with-smartpay
|
50
|
+
```
|
51
|
+
|
52
|
+
#### Add Smartpay
|
53
|
+
|
54
|
+
```sh
|
55
|
+
cd app-with-smartpay
|
56
|
+
bundle add smartpay
|
57
|
+
```
|
58
|
+
|
59
|
+
#### Generator
|
60
|
+
|
61
|
+
```sh
|
62
|
+
bundle exec rails generate smartpay:install
|
63
|
+
```
|
64
|
+
|
65
|
+
This introduces 4 changes for a pre-built Smartpay Checkout example:
|
66
|
+
|
67
|
+
> 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
|
+
> 2. A new controller - `app/controllers/smartpays_controller.rb`. This is where you can see how a Checkout session is configured & created.
|
69
|
+
> 3. A new view - `app/views/smartpays/index.html.erb`. The minimum frontend required.
|
70
|
+
> 4. A new route in config/routes.rb.
|
71
|
+
|
72
|
+
#### Fill in your API keys
|
73
|
+
|
74
|
+
Edit the keys with your own credentials in `config/initializers/smartpay.rb`.
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
...
|
78
|
+
config.public_key = '<YOUR_PUBLIC_KEY>' # the one starts with pk_test_
|
79
|
+
config.secret_key = '<YOUR_API_SECRET>' # the one starts with sk_test_
|
80
|
+
...
|
81
|
+
```
|
82
|
+
|
83
|
+
#### Start your server
|
84
|
+
|
85
|
+
```sh
|
86
|
+
bundle exec rails server
|
87
|
+
```
|
16
88
|
|
17
|
-
|
89
|
+
### Test with Checkout Session
|
18
90
|
|
19
|
-
|
91
|
+
Visit [http://localhost:3000/smartpays](http://localhost:3000/smartpays).
|
20
92
|
|
21
|
-
|
93
|
+
Click the `checkout` button on the page to be redirected to Smartpay's Checkout.
|
22
94
|
|
23
|
-
|
95
|
+
To try out different cases, you can use the following test credit cards for different cases:
|
24
96
|
|
25
|
-
|
97
|
+
- Payment succeeds: `4242 4242 4242 4242`
|
98
|
+
- Payment is declined: `4100 0000 0000 0019`
|
26
99
|
|
27
100
|
## Development
|
28
101
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators"
|
4
|
+
|
5
|
+
module Smartpay
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
def install
|
10
|
+
template "initializer.rb", "config/initializers/smartpay.rb"
|
11
|
+
template "controller.rb", "app/controllers/smartpays_controller.rb"
|
12
|
+
template "assets/stylesheets/demo.css", "app/assets/stylesheets/demo.css"
|
13
|
+
directory "views", "app/views/smartpays"
|
14
|
+
|
15
|
+
route "resources :smartpays, only: [:index, :create]"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -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
|
+
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
class SmartpaysController < ApplicationController
|
2
|
+
def new
|
3
|
+
end
|
4
|
+
|
5
|
+
def create
|
6
|
+
session = Smartpay::Api.create_checkout_session(
|
7
|
+
{
|
8
|
+
"customerInfo": {
|
9
|
+
"emailAddress": "success@smartpay.co",
|
10
|
+
"firstName": nil,
|
11
|
+
"lastName": nil,
|
12
|
+
"firstNameKana": nil,
|
13
|
+
"lastNameKana": nil,
|
14
|
+
"address": nil,
|
15
|
+
"phoneNumber": nil,
|
16
|
+
"dateOfBirth": nil,
|
17
|
+
"legalGender": nil,
|
18
|
+
"reference": nil
|
19
|
+
},
|
20
|
+
"orderData": {
|
21
|
+
"amount": 250,
|
22
|
+
"currency": "JPY",
|
23
|
+
"captureMethod": nil,
|
24
|
+
"confirmationMethod": nil,
|
25
|
+
"coupons": nil,
|
26
|
+
"shippingInfo": {
|
27
|
+
"address": {
|
28
|
+
"line1": "line1",
|
29
|
+
"line2": nil,
|
30
|
+
"line3": nil,
|
31
|
+
"line4": nil,
|
32
|
+
"line5": nil,
|
33
|
+
"subLocality": nil,
|
34
|
+
"locality": "locality",
|
35
|
+
"administrativeArea": nil,
|
36
|
+
"postalCode": "123",
|
37
|
+
"country": "JP"},
|
38
|
+
"addressType": nil},
|
39
|
+
"lineItemData": [{
|
40
|
+
"price": nil,
|
41
|
+
"priceData": {
|
42
|
+
"productData": {
|
43
|
+
"name": "レブロン 18 LOW",
|
44
|
+
"brand": nil,
|
45
|
+
"categories": nil,
|
46
|
+
"description": nil,
|
47
|
+
"gtin": nil,
|
48
|
+
"images": nil,
|
49
|
+
"reference": nil,
|
50
|
+
"url": nil,
|
51
|
+
"metadata": nil},
|
52
|
+
"amount": 250,
|
53
|
+
"currency": "JPY",
|
54
|
+
"metadata": nil},
|
55
|
+
"quantity": 1,
|
56
|
+
"description": nil,
|
57
|
+
"metadata": nil
|
58
|
+
}]
|
59
|
+
},
|
60
|
+
"reference": "order_ref_1234567",
|
61
|
+
"metadata": nil,
|
62
|
+
"successUrl": "https://docs.smartpay.co/example-pages/checkout-successful",
|
63
|
+
"cancelUrl": "https://docs.smartpay.co/example-pages/checkout-canceled",
|
64
|
+
"test": true
|
65
|
+
})
|
66
|
+
redirect_to session.redirect_url
|
67
|
+
end
|
68
|
+
end
|
data/lib/smartpay/api.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rest-client'
|
4
|
+
|
5
|
+
module Smartpay
|
6
|
+
class Client
|
7
|
+
class << self
|
8
|
+
def post(path, payload = {})
|
9
|
+
response = RestClient::Request.execute(method: :post, url: api_url(path), headers: headers, timeout: timeout, payload: payload.to_json)
|
10
|
+
JSON.parse(response.body, symbolize_names: true)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def api_url(path)
|
16
|
+
"#{Smartpay.configuration.api_url}#{path}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def timeout
|
20
|
+
Smartpay.configuration.post_timeout
|
21
|
+
end
|
22
|
+
|
23
|
+
def headers
|
24
|
+
{
|
25
|
+
accept: :json,
|
26
|
+
content_type: :json,
|
27
|
+
Authorization: "Basic #{secret_key}"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def secret_key
|
32
|
+
Smartpay.configuration.secret_key
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Smartpay
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :post_timeout
|
6
|
+
attr_accessor :public_key, :secret_key, :api_url, :checkout_url
|
7
|
+
|
8
|
+
DEFAULT_TIMEOUT_SETTING = 30
|
9
|
+
DEFAULT_API_URL = 'https://api.smartpay.co'
|
10
|
+
DEFAULT_CHECKOUT_URL = 'https://checkout.smartpay.co'
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@post_timeout = DEFAULT_TIMEOUT_SETTING
|
14
|
+
@api_url = DEFAULT_API_URL
|
15
|
+
@checkout_url = DEFAULT_CHECKOUT_URL
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Smartpay
|
4
|
+
module Responses
|
5
|
+
class CheckoutSession
|
6
|
+
attr_reader :response
|
7
|
+
|
8
|
+
def initialize(response)
|
9
|
+
@response = response
|
10
|
+
end
|
11
|
+
|
12
|
+
def redirect_url
|
13
|
+
URI.escape("#{checkout_url}/login?session-id=#{response[:id]}&public-key=#{public_key}")
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def checkout_url
|
19
|
+
Smartpay.configuration.checkout_url
|
20
|
+
end
|
21
|
+
|
22
|
+
def public_key
|
23
|
+
Smartpay.configuration.public_key
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/smartpay/version.rb
CHANGED
data/lib/smartpay.rb
CHANGED
@@ -1,8 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'json'
|
4
|
+
|
3
5
|
require_relative "smartpay/version"
|
6
|
+
require_relative 'smartpay/configuration'
|
7
|
+
require_relative 'smartpay/client'
|
8
|
+
require_relative 'smartpay/api'
|
9
|
+
require_relative 'smartpay/responses/checkout_session'
|
4
10
|
|
5
11
|
module Smartpay
|
6
|
-
class
|
7
|
-
|
12
|
+
class << self
|
13
|
+
attr_accessor :configuration
|
14
|
+
|
15
|
+
def configuration
|
16
|
+
@configuration ||= Smartpay::Configuration.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def configure
|
20
|
+
yield(configuration)
|
21
|
+
end
|
22
|
+
end
|
8
23
|
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartpay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Smartpay
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
12
|
-
dependencies:
|
11
|
+
date: 2021-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
13
41
|
description:
|
14
42
|
email:
|
15
43
|
- uxe@smartpay.co
|
@@ -27,7 +55,16 @@ files:
|
|
27
55
|
- Rakefile
|
28
56
|
- bin/console
|
29
57
|
- bin/setup
|
58
|
+
- lib/generators/smartpay/install_generator.rb
|
59
|
+
- lib/generators/smartpay/templates/assets/stylesheets/demo.css
|
60
|
+
- lib/generators/smartpay/templates/controller.rb
|
61
|
+
- lib/generators/smartpay/templates/initializer.rb
|
62
|
+
- lib/generators/smartpay/templates/views/index.html.erb
|
30
63
|
- lib/smartpay.rb
|
64
|
+
- lib/smartpay/api.rb
|
65
|
+
- lib/smartpay/client.rb
|
66
|
+
- lib/smartpay/configuration.rb
|
67
|
+
- lib/smartpay/responses/checkout_session.rb
|
31
68
|
- lib/smartpay/version.rb
|
32
69
|
homepage: https://smartpay.co
|
33
70
|
licenses:
|
@@ -51,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
88
|
- !ruby/object:Gem::Version
|
52
89
|
version: '0'
|
53
90
|
requirements: []
|
54
|
-
rubygems_version: 3.
|
91
|
+
rubygems_version: 3.0.9
|
55
92
|
signing_key:
|
56
93
|
specification_version: 4
|
57
94
|
summary: The Smartpay Ruby SDK offers easy access to Smartpay API from applications
|