checkout_sdk 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bba173b4cd357fc0413c4a464572237123622e7fc14f67f0808d4391570ea530
4
+ data.tar.gz: 238febcf16b81bc9d2bbc989081396fb3ff0126e00bc94b94c7c450fb13cd5f9
5
+ SHA512:
6
+ metadata.gz: 64992def6eef9f6d839b7716e27f9d77cca12750bc30745eca5572bb39509cdff3141636c59c1461edd83407528ea07e16540a378fdd115894205f62b956ce9e
7
+ data.tar.gz: f420dc2e38b57ff7e38f0eff734e3e3fe369b74116d671e77b31c5f39575cee016f8550b6342dffaa5bd61183ee045630e6e1fe950a2088b445c727bc7db8edc
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.7
7
+ before_install: gem install bundler -v 1.16.5
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ checkout (0.1.0)
5
+ excon
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ excon (0.67.0)
13
+ method_source (0.9.2)
14
+ pry (0.12.2)
15
+ coderay (~> 1.1.0)
16
+ method_source (~> 0.9.0)
17
+ rake (10.5.0)
18
+ rspec (3.8.0)
19
+ rspec-core (~> 3.8.0)
20
+ rspec-expectations (~> 3.8.0)
21
+ rspec-mocks (~> 3.8.0)
22
+ rspec-core (3.8.2)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-expectations (3.8.4)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-mocks (3.8.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-support (3.8.2)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.16)
37
+ checkout!
38
+ pry
39
+ rake (~> 10.0)
40
+ rspec (~> 3.0)
41
+
42
+ BUNDLED WITH
43
+ 1.17.2
@@ -0,0 +1,63 @@
1
+ # Checkout
2
+
3
+ You are reading documentation for version: 0.1.0
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'checkout_sdk'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install checkout_sdk
20
+
21
+ ## Configuration
22
+
23
+ API keys must be configured in the gem setup. You can do this anywhere in your application before you make API calls using the gem.
24
+
25
+ ```ruby
26
+ Checkout.configure do |config|
27
+ config.secret_key = ENV['SECRET_KEY']
28
+ config.public_key = ENV['PUBLIC_KEY']
29
+ config.base_url = ENV['BASE_URL']
30
+ end
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ```ruby
36
+ p = Checkout::PaymentRequestSource.new
37
+ p.type = "card"
38
+ p.card_number = "4242424242424242"
39
+ p.card_expiry_month = 6
40
+ p.card_expiry_year = 2025
41
+ p.card_name = "Bruce Wayne"
42
+ p.card_cvv = "100"
43
+ p.amount = 2022
44
+ p.currency = "GBP"
45
+ p.capture = true
46
+ p.threeds_enabled = false
47
+ p.threeds_attempt_n3d = false
48
+ p.recipient_dob = "1992-04-06"
49
+ p.recipient_account_number = "1234567890"
50
+ p.recipient_zip = "12345"
51
+ p.recipient_last_name = "Elmo"
52
+ p.risk_enabled = true
53
+ p.billing_descriptor_name = "Nancy"
54
+ p.billing_descriptor_city = "Berlin"
55
+ p.processing_mid = "Checkout"
56
+
57
+ r = Checkout::ApiResource.new
58
+ r.request_payments(p)
59
+ ```
60
+
61
+ ## Tests
62
+
63
+ $ rspec
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "checkout"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "checkout/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "checkout_sdk"
7
+ spec.version = Checkout::VERSION
8
+ spec.authors = ["Khalid Jazaerly"]
9
+ spec.email = ["khalid.jaz@gmail.com"]
10
+
11
+ spec.summary = %q{A Ruby API wrapper for checkout.com.}
12
+ spec.description = %q{A Ruby API wrapper for checkout.com.}
13
+ spec.homepage = "http://checkout.com"
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_dependency "excon"
29
+ end
@@ -0,0 +1,22 @@
1
+ require "checkout/configuration"
2
+ require "checkout/api_resource"
3
+ require "checkout/data/capture_payment"
4
+ require "checkout/data/payment_request_source"
5
+
6
+ module Checkout
7
+ class << self
8
+ attr_accessor :configuration
9
+ end
10
+
11
+ def self.configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
15
+ def self.reset
16
+ @configuration = Configuration.new
17
+ end
18
+
19
+ def self.configure
20
+ yield(configuration)
21
+ end
22
+ end
@@ -0,0 +1,59 @@
1
+ require "excon"
2
+
3
+ class Checkout::ApiResource
4
+ attr_reader :checkout_connection
5
+
6
+ def initialize
7
+ @checkout_connection = Excon.new("#{Checkout.configuration.base_url}", persistent: true)
8
+ end
9
+
10
+ def request_payments(data_object)
11
+ post_request("/payments", data_object.data)
12
+ end
13
+
14
+ def capture_payment(data_object)
15
+ post_request("/payments/#{data_object.id}/captures", data_object.data)
16
+ end
17
+
18
+ def refund_payment(data_object)
19
+ post_request("/payments/#{data_object.id}/refunds", data_object.data)
20
+ end
21
+
22
+ def void_payment(data_object)
23
+ post_request("/payments/#{data_object.id}/voids", data_object.data)
24
+ end
25
+
26
+ def add_payment_source(data_object)
27
+ post_request("/sources", data_object.data)
28
+ end
29
+
30
+ def request_token(data_object)
31
+ post_request("/tokens", data_object.data)
32
+ end
33
+
34
+ def get_payment_details(id)
35
+ get("/payments/#{id}")
36
+ end
37
+
38
+ def get_payment_actions(id)
39
+ get("/payments/#{id}/actions")
40
+ end
41
+
42
+ private
43
+
44
+ def post_request(path, data_object)
45
+ checkout_connection.post(
46
+ path: path,
47
+ body: data_object.to_json,
48
+ headers: { "Content-Type" => "application/json",
49
+ "Authorization" => "#{Checkout.configuration.secret_key}" }
50
+ )
51
+ end
52
+
53
+ def get(path)
54
+ checkout_connection.get(
55
+ path: path,
56
+ headers: { "Authorization" => "#{Checkout.configuration.secret_key}" }
57
+ )
58
+ end
59
+ end
@@ -0,0 +1,9 @@
1
+ class Checkout::Configuration
2
+ attr_accessor :secret_key, :public_key, :base_url
3
+
4
+ def initialize
5
+ @secret_key = nil
6
+ @public_key = nil
7
+ @base_url = nil
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class Checkout::CapturePayment
2
+ attr_accessor :id, :amount, :reference, :metadata
3
+
4
+ def data
5
+ {
6
+ amount: amount,
7
+ reference: reference,
8
+ metadata: metadata
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,144 @@
1
+ class Checkout::PaymentRequestSource
2
+ attr_accessor :type, :token, :billing_address_line1, :billing_address_line2, :billing_city, :billing_state,
3
+ :billing_zip, :billing_country, :phone_country_code, :phone_number, :amount,
4
+ :currency, :payment_type, :reference, :description, :capture, :capture_on, :customer_id,
5
+ :customer_email, :customer_name, :billing_descriptor, :billing_descriptor_name,
6
+ :billing_descriptor_city, :shipping_address_line1, :shipping_address_line2, :shipping_city,
7
+ :shipping_state, :shipping_zip, :shipping_country, :shipping_phone_country_code,
8
+ :shipping_phone_number, :threeds_enabled, :threeds_attempt_n3d, :threeds_eci,
9
+ :threeds_cryptogram, :threeds_xid, :threeds_version, :previous_payment_id, :risk_enabled,
10
+ :success_url, :failure_url, :payment_ip, :recipient_dob, :recipient_account_number,
11
+ :recipient_zip, :recipient_last_name, :processing_mid, :metadata, :cvv, :id, :card_number,
12
+ :card_expiry_month, :card_expiry_year, :card_name, :card_cvv, :card_stored, :customer_id,
13
+ :customer_email
14
+
15
+ def data
16
+ { source: source(type),
17
+ amount: amount,
18
+ currency: currency,
19
+ payment_type: payment_type,
20
+ reference: reference,
21
+ description: description,
22
+ capture: capture,
23
+ capture_on: capture_on,
24
+ customer: {
25
+ id: customer_id,
26
+ email: customer_email,
27
+ name: customer_name
28
+ },
29
+ billing_descriptor: {
30
+ name: billing_descriptor_name,
31
+ city: billing_descriptor_city
32
+ },
33
+ shipping: {
34
+ address: {
35
+ address_line1: shipping_address_line1,
36
+ address_line2: shipping_address_line2,
37
+ city: shipping_city,
38
+ state: shipping_state,
39
+ zip: shipping_zip,
40
+ country: shipping_country
41
+ },
42
+ phone: {
43
+ country_code: shipping_phone_country_code,
44
+ number: shipping_phone_number
45
+ }
46
+ },
47
+ "3ds" => {
48
+ enabled: threeds_enabled,
49
+ attempt_n3d: threeds_attempt_n3d,
50
+ eci: threeds_eci,
51
+ cryptogram: threeds_cryptogram,
52
+ xid: threeds_xid,
53
+ version: threeds_version
54
+ },
55
+ previous_payment_id: previous_payment_id,
56
+ risk: {
57
+ enabled: risk_enabled
58
+ },
59
+ success_url: success_url,
60
+ failure_url: failure_url,
61
+ payment_ip: payment_ip,
62
+ recipient: {
63
+ dob: recipient_dob,
64
+ account_number: recipient_account_number,
65
+ zip: recipient_zip,
66
+ last_name: recipient_last_name
67
+ },
68
+ processing: {
69
+ mid: processing_mid
70
+ },
71
+ metadata: metadata
72
+ }
73
+ end
74
+
75
+ private
76
+
77
+ def source(type)
78
+ case type
79
+ when "id" then id_type
80
+ when "token" then token_type
81
+ when "card" then card_type
82
+ when "customer" then customer_type
83
+ end
84
+ end
85
+
86
+ def token_type
87
+ {
88
+ type: type,
89
+ token: token,
90
+ billing_address: {
91
+ address_line1: billing_address_line1,
92
+ address_line2: billing_address_line2,
93
+ city: billing_city,
94
+ state: billing_state,
95
+ zip: billing_zip,
96
+ country: billing_country
97
+ },
98
+ phone: {
99
+ country_code: phone_country_code,
100
+ number: phone_number
101
+ },
102
+ }
103
+ end
104
+
105
+ def card_type
106
+ {
107
+ type: type,
108
+ number: card_number,
109
+ expiry_month: card_expiry_month,
110
+ expiry_year: card_expiry_year,
111
+ name: card_name,
112
+ cvv: card_cvv,
113
+ stored: card_stored,
114
+ billing_address: {
115
+ address_line1: billing_address_line1,
116
+ address_line2: billing_address_line2,
117
+ city: billing_city,
118
+ state: billing_state,
119
+ zip: billing_zip,
120
+ country: billing_country
121
+ },
122
+ phone: {
123
+ country_code: phone_country_code,
124
+ number: phone_number
125
+ },
126
+ }
127
+ end
128
+
129
+ def id_type
130
+ {
131
+ type: type,
132
+ id: id,
133
+ cvv: cvv
134
+ }
135
+ end
136
+
137
+ def customer_type
138
+ {
139
+ type: type,
140
+ id: customer_id,
141
+ email: customer_email
142
+ }
143
+ end
144
+ end
@@ -0,0 +1,40 @@
1
+ class Checkout::PaymentSource
2
+ attr_accessor :type, :reference, :billing_address_line1, :billing_address_line2,
3
+ :billing_city, :billing_state, :billing_zip, :billing_country,
4
+ :phone_country_code, :phone_number, :customer_id,
5
+ :customer_email, :customer_name, :source_data_first_name,
6
+ :source_data_last_name, :source_data_account_iban, :source_data_bic,
7
+ :source_data_billing_descriptor, :source_data_mandate_type
8
+
9
+ def data
10
+ {
11
+ type: type,
12
+ reference: reference,
13
+ billing_address: {
14
+ address_line1: billing_address_line1,
15
+ address_line2: billing_address_line2,
16
+ city: billing_city,
17
+ state: billing_state,
18
+ zip: billing_zip,
19
+ country: billing_country
20
+ },
21
+ phone: {
22
+ country_code: phone_country_code,
23
+ number: phone_number
24
+ },
25
+ customer: {
26
+ id: customer_id,
27
+ email: customer_email,
28
+ name: customer_name
29
+ },
30
+ source_data: {
31
+ first_name: source_data_first_name,
32
+ last_name: source_data_last_name,
33
+ account_iban: source_data_account_iban,
34
+ bic: source_data_bic,
35
+ billing_descriptor: source_data_billing_descriptor,
36
+ mandate_type: source_data_mandate_type
37
+ }
38
+ }
39
+ end
40
+ end
@@ -0,0 +1,11 @@
1
+ class Checkout::RefundPayment
2
+ attr_accessor :id, :amount, :reference, :metadata
3
+
4
+ def data
5
+ {
6
+ amount: amount,
7
+ reference: reference,
8
+ metadata: metadata
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,67 @@
1
+ class Checkout::RequestToken
2
+ attr_accessor :type, :token_data_version, :token_data_data, :token_data_signature,
3
+ :token_data_header, :token_data_signature, :token_data_protocolVersion,
4
+ :token_data_signedMessage, :card_number, :card_expiry_month, :card_expiry_year,
5
+ :card_name, :card_cvv, :billing_address_line1, :billing_address_line2, :billing_city,
6
+ :billing_state, :billing_zip, :billing_country, :phone_country_code, :phone_number
7
+
8
+ def data
9
+ if type == "card"
10
+ card_type
11
+ else
12
+ {
13
+ type: type,
14
+ token_data: token_data(type)
15
+ }
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def token_data(type)
22
+ case type
23
+ when "applepay" then applepay_type
24
+ when "googlepay" then googlepay_type
25
+ end
26
+ end
27
+
28
+ def applepay_type
29
+ {
30
+ version: token_data_version,
31
+ data: token_data_data,
32
+ signature: token_data_signature,
33
+ header: token_data_header
34
+ }
35
+ end
36
+
37
+ def googlepay_type
38
+ {
39
+ signature: token_data_signature,
40
+ protocolVersion: token_data_protocolVersion,
41
+ signedMessage: token_data_signedMessage
42
+ }
43
+ end
44
+
45
+ def card_type
46
+ {
47
+ type: type,
48
+ number: card_number,
49
+ expiry_month: card_expiry_month,
50
+ expiry_year: card_expiry_year,
51
+ name: card_name,
52
+ cvv: card_cvv,
53
+ billing_address: {
54
+ address_line1: billing_address_line1,
55
+ address_line2: billing_address_line2,
56
+ city: billing_city,
57
+ state: billing_state,
58
+ zip: billing_zip,
59
+ country: billing_country
60
+ },
61
+ phone: {
62
+ country_code: phone_country_code,
63
+ number: phone_number
64
+ }
65
+ }
66
+ end
67
+ end
@@ -0,0 +1,10 @@
1
+ class Checkout::VoidPayment
2
+ attr_accessor :id, :reference, :metadata
3
+
4
+ def data
5
+ {
6
+ reference: reference,
7
+ metadata: metadata
8
+ }
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Checkout
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: checkout_sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Khalid Jazaerly
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: excon
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A Ruby API wrapper for checkout.com.
84
+ email:
85
+ - khalid.jaz@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - checkout.gemspec
100
+ - lib/checkout.rb
101
+ - lib/checkout/api_resource.rb
102
+ - lib/checkout/configuration.rb
103
+ - lib/checkout/data/capture_payment.rb
104
+ - lib/checkout/data/payment_request_source.rb
105
+ - lib/checkout/data/payment_source.rb
106
+ - lib/checkout/data/refund_payment.rb
107
+ - lib/checkout/data/request_token.rb
108
+ - lib/checkout/data/void_payment.rb
109
+ - lib/checkout/version.rb
110
+ homepage: http://checkout.com
111
+ licenses: []
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.0.1
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A Ruby API wrapper for checkout.com.
132
+ test_files: []