smartpay 0.1.0 → 0.2.3

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: 38d6c56f2c6abb2cf337532c6e3d10943111aed67b585d62c5fb6bdc1ab26198
4
- data.tar.gz: 8f67b047ab3bfb8cc28c503657ea3f02bb83f6cab0fd25ce04ca9eab90853bb2
3
+ metadata.gz: 0c6d6af18ab67f641631f6e67525ae39c64286ae716819fa2d96658b0571f83b
4
+ data.tar.gz: 64a89a61dd9cfec7fffad3735bea54ad22c5387e2b68bc8caa54148803aea394
5
5
  SHA512:
6
- metadata.gz: 87a360308fd0f6d5b5ec8cb73c28f611c03ae465ccb16bd5fc53d989812e95b84e1873890fa011fd27adde18d3f953c1974a26499f4b5beae36b4c79db6aa25b
7
- data.tar.gz: 020bc848c1ddb5bfe842bac6e78b622cde388fcd33de9719f5e877a2583e2b47aaa733c0e626d7aa7a8e41c35d7fc945feef9b1c02bd95eadc217211c7cd96ea
6
+ metadata.gz: 7f2ca92bd0867e03a3f2ab3f2c964bfdb1ead71ade148ea753b28aec3ee57aed4d7ab394041620bba30a02055839b214f164e562ed6281e96bf53968a958e6b4
7
+ data.tar.gz: 1426c5205f369b614791c2b8277df030f8f693e31b1caf9ac36f8cfef017a95570599ee957c2f615401fb57a6b95f38720d9cdf4296b3cdf8563dc4a5110dde0
data/README.md CHANGED
@@ -1,28 +1,101 @@
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
+ ## 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
- Add this line to your application's Gemfile:
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
- And then execute:
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_api_key` and `config.private_api_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_api_key = '<YOUR_PUBLIC_API_KEY>' # the one starts with pk_test_
79
+ config.private_api_key = '<YOUR_PRIVATE_API_KEY>' # 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
- $ bundle install
89
+ ### Test with Checkout Session
18
90
 
19
- Or install it yourself as:
91
+ Visit [http://localhost:3000/smartpays](http://localhost:3000/smartpays).
20
92
 
21
- $ gem install smartpay
93
+ Click the `checkout` button on the page to be redirected to Smartpay's Checkout.
22
94
 
23
- ## Usage
95
+ To try out different cases, you can use the following test credit cards for different cases:
24
96
 
25
- TODO: Write usage instructions here
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
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ Smartpay.configure do |config|
4
+ config.api_url = 'https://api.smartpay.co/smartpayments'
5
+ config.checkout_url = 'https://checkout.smartpay.co'
6
+ config.public_api_key = 'pk_test_'
7
+ config.private_api_key = 'sk_test_'
8
+ end
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <%= stylesheet_link_tag "demo" %>
5
+ </head>
6
+ <body>
7
+ <%= form_tag smartpays_path do %>
8
+ <%= submit_tag 'Checkout' %>
9
+ <% end %>
10
+ </body>
11
+ </html>
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rest-client'
4
+
3
5
  module Smartpay
4
6
  class Client
5
7
  class << self
@@ -22,12 +24,12 @@ module Smartpay
22
24
  {
23
25
  accept: :json,
24
26
  content_type: :json,
25
- Authorization: "Basic #{api_secret}"
27
+ Authorization: "Basic #{private_api_key}"
26
28
  }
27
29
  end
28
30
 
29
- def api_secret
30
- Smartpay.configuration.api_secret
31
+ def private_api_key
32
+ Smartpay.configuration.private_api_key
31
33
  end
32
34
  end
33
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_api_key, :private_api_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,7 @@ module Smartpay
10
10
  end
11
11
 
12
12
  def redirect_url
13
- URI.escape("#{checkout_url}/login?session-id=#{response[:id]}&public-key=#{public_key}")
13
+ URI.escape("#{checkout_url}/login?session-id=#{response[:id]}&public-key=#{public_api_key}")
14
14
  end
15
15
 
16
16
  private
@@ -19,8 +19,8 @@ module Smartpay
19
19
  Smartpay.configuration.checkout_url
20
20
  end
21
21
 
22
- def public_key
23
- Smartpay.configuration.public_key
22
+ def public_api_key
23
+ Smartpay.configuration.public_api_key
24
24
  end
25
25
  end
26
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Smartpay
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.3"
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.1.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Smartpay
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-18 00:00:00.000000000 Z
11
+ date: 2021-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
- description:
41
+ description:
42
42
  email:
43
43
  - uxe@smartpay.co
44
44
  executables: []
@@ -55,6 +55,11 @@ files:
55
55
  - Rakefile
56
56
  - bin/console
57
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
58
63
  - lib/smartpay.rb
59
64
  - lib/smartpay/api.rb
60
65
  - lib/smartpay/client.rb
@@ -68,7 +73,7 @@ metadata:
68
73
  homepage_uri: https://smartpay.co
69
74
  source_code_uri: https://github.com/smartpay-co/sdk-ruby
70
75
  changelog_uri: https://github.com/smartpay-co/sdk-ruby/blob/main/CHANGELOG.md
71
- post_install_message:
76
+ post_install_message:
72
77
  rdoc_options: []
73
78
  require_paths:
74
79
  - lib
@@ -83,8 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
88
  - !ruby/object:Gem::Version
84
89
  version: '0'
85
90
  requirements: []
86
- rubygems_version: 3.0.3
87
- signing_key:
91
+ rubygems_version: 3.0.9
92
+ signing_key:
88
93
  specification_version: 4
89
94
  summary: The Smartpay Ruby SDK offers easy access to Smartpay API from applications
90
95
  written in Ruby.