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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 574ea8c0a8437a946bebba2924965c3a5c62ee8c4ccc990a3222491ccebb30ee
4
- data.tar.gz: fb334df6541a5869c2ad7df5250f69f7c7593e6b5f804fdcbb3d878298a82cbd
3
+ metadata.gz: 6c3f54543398cb0fc174621f0527f86329337fb0bce18911f334b32389358db6
4
+ data.tar.gz: fd7f015bfa49ec0bdf491e34113048098cae02c782abf3b1a8e8bf2df1799387
5
5
  SHA512:
6
- metadata.gz: 9778570f0c65d94e1f5006ce19254ceef5cfc369f5b654579b091777048ce20c6ba317c0e9fa307de9d8a46dd4feda0ed774d2ce401786c059375d93f3b9e054
7
- data.tar.gz: a8aca7526235571495966f9f68dbc7dfe4693cf56d832c5a01543993fd88cce0c19af0a14a0137e7c42d6287485bb6c200c8cc3596984eaa6798bdf592be3ab6
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/smartpay`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ The Smartpay Ruby library offers easy access to Smartpay API from applications written in Ruby.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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
- Add the latest version of Smartpay to your project's dependencies:
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
- $ bundle add smartpay
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
- Or, you can add this line to your application's Gemfile and specify the version restriction:
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
- gem 'smartpay', "~> 0.1.0"
92
+ session = Smartpay::Api.create_checkout_session(payload)
17
93
  ```
18
94
 
19
- And then execute:
95
+ Then, you can redirect your customer to the session url by calling `redirect_url`:
20
96
 
21
- $ bundle install
97
+ ```ruby
98
+ session.redirect_url
99
+ ```
22
100
 
23
- ## Usage for Ruby on Rails
101
+ ## Use with your favorite frameworks
24
102
 
25
- After installed the gem package, you can generate relevant files with:
103
+ ### Ruby on Rails (RoR)
26
104
 
27
- $ bundle exec rails generate smartpay:install
105
+ #### Install Rails
28
106
 
29
- This will introduce 4 changes, including a simple example for checkout session flow:
107
+ ```sh
108
+ gem install rails
109
+ ```
30
110
 
31
- 1. Add new initializer in `config/initializers/smartpay.rb`
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
- ### Setup Server Credentials
113
+ ```sh
114
+ rails new app-with-smartpay
115
+ ```
116
+
117
+ #### Add Smartpay
37
118
 
38
- Make sure you have the credentials (API key & secret) from Smartpay before you can have a working integration.
39
- You can find your credentials at the `settings > credentials` page on your [dashboard](https://merchant.smartpay.co/settings/credentials).
119
+ ```sh
120
+ cd app-with-smartpay
121
+ bundle add smartpay
122
+ ```
40
123
 
41
- Update your API key and secret to the fields `public_key` and `api_secret` in `config/initializers/smartpay.rb`.
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
- Start your server and navigate to `http://localhost:3000/smartpays`.
156
+ Visit [http://localhost:3000/smartpays](http://localhost:3000/smartpays).
46
157
 
47
- Click the `checkout` button to be redirected to the Checkout page.
158
+ Click the `checkout` button on the page to be redirected to Smartpay's Checkout.
48
159
 
49
- Replace any of these test accounts to the field `customerInfo.emailAddress` of request payload in `app/controllers/smartpays_controller.rb` to simulate a payment.
160
+ To try out different cases, you can use the following test credit cards for different cases:
50
161
 
51
- 1. Payment succeeds: `success@smartpay.co`
52
- 2. Payment requires authentication: `auth.required@smartpay.co`
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.re/smartpayments'
5
- config.checkout_url = 'https://checkout.smartpay.re'
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.api_secret = 'sk_test_'
7
+ config.secret_key = 'sk_test_'
8
8
  end
@@ -1,5 +1,8 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
+ <head>
4
+ <%= stylesheet_link_tag "demo" %>
5
+ </head>
3
6
  <body>
4
7
  <%= form_tag smartpays_path do %>
5
8
  <%= submit_tag 'Checkout' %>
@@ -24,12 +24,12 @@ module Smartpay
24
24
  {
25
25
  accept: :json,
26
26
  content_type: :json,
27
- Authorization: "Basic #{api_secret}"
27
+ Authorization: "Basic #{private_api_key}"
28
28
  }
29
29
  end
30
30
 
31
- def api_secret
32
- Smartpay.configuration.api_secret
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, :api_secret, :api_url, :checkout_url
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'
@@ -13,6 +13,14 @@ module Smartpay
13
13
  URI.escape("#{checkout_url}/login?session-id=#{response[:id]}&public-key=#{public_key}")
14
14
  end
15
15
 
16
+ def as_hash
17
+ @response
18
+ end
19
+
20
+ def as_json
21
+ @response.to_json
22
+ end
23
+
16
24
  private
17
25
 
18
26
  def checkout_url
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Smartpay
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.4"
5
5
  end
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.0
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-18 00:00:00.000000000 Z
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