checkout_sdk 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b22fce47bec3da9a803c2697f80ab2284c8a615b
4
- data.tar.gz: dba31fa4811255bed5e2b0bf2f025cca47430eb6
2
+ SHA256:
3
+ metadata.gz: f0cc02510133333f0aa24e032494518e76e1545d895d0bc80ee042685f53a1b8
4
+ data.tar.gz: 66b207f7ab757b17d4ec673ed369cfc7bd55caafce56fcfab37f7863fac99936
5
5
  SHA512:
6
- metadata.gz: 4ce5ab3b932d135553d09cdf556706dabc1b2f6b39899d2ff67cfe45c5ec3664977f7ce19dd86cb1fa42fcd4c1ad3840f828ac44fa75c6bc1da18b3d8edaae83
7
- data.tar.gz: 5a589bb7a2f624b921757748c11272c4622aee2891db7404a8688def702ce6c7c9ea3c7b69cb789c0a8e4e1e5380ce36abe2f8c161ae31303aa994444066a818
6
+ metadata.gz: 9169313cb4facab9f0bee3ae7308b88a72f3e44f30bcc56e30aca876a91e74bfc4a16571b1cea010741591fbdebe27b970491bdae204f09ad5804981642dcd34
7
+ data.tar.gz: 311981be44e7d73bac6d9e1a60532941e406f926e6b738e5660e6666cb5afc6e8b946827b57421a4f5ee4a1ed6bdcd86587768a0fe3dc4ae26761b882e65f9a1
data/.gitignore ADDED
@@ -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
data/.travis.yml ADDED
@@ -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
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ checkout_sdk (0.1.2)
5
+ excon (~> 0.66.0)
6
+ multi_json (~> 1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.2)
12
+ diff-lcs (1.3)
13
+ excon (0.66.0)
14
+ method_source (0.9.2)
15
+ multi_json (1.13.1)
16
+ pry (0.11.3)
17
+ coderay (~> 1.1.0)
18
+ method_source (~> 0.9.0)
19
+ rake (10.5.0)
20
+ rspec (3.8.0)
21
+ rspec-core (~> 3.8.0)
22
+ rspec-expectations (~> 3.8.0)
23
+ rspec-mocks (~> 3.8.0)
24
+ rspec-core (3.8.2)
25
+ rspec-support (~> 3.8.0)
26
+ rspec-expectations (3.8.4)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-mocks (3.8.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.8.0)
32
+ rspec-support (3.8.2)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ bundler (~> 1.16)
39
+ checkout_sdk!
40
+ pry (~> 0.11.3)
41
+ rake (~> 10.0)
42
+ rspec (~> 3.0)
43
+
44
+ BUNDLED WITH
45
+ 1.17.3
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # CheckoutSdk
2
+
3
+ You are reading documentation for version: 0.1.3
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
+ CheckoutSdk.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 = CheckoutSdk::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 = "CheckoutSdk"
56
+
57
+ r = CheckoutSdk::ApiResource.new
58
+ r.request_payments(p)
59
+ ```
60
+
61
+ ## Tests
62
+
63
+ $ rspec
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "checkout_sdk"
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__)
data/bin/setup ADDED
@@ -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,23 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "checkout_sdk/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "checkout_sdk"
7
+ spec.version = CheckoutSdk::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
+ spec.files = `git ls-files`.split("\n")
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_development_dependency "bundler", "~> 1.16"
18
+ spec.add_development_dependency "rake", "~> 10.0"
19
+ spec.add_development_dependency "rspec", "~> 3.0"
20
+ spec.add_development_dependency "pry", "~> 0.11.3"
21
+ spec.add_dependency "multi_json", '~> 1.0'
22
+ spec.add_dependency "excon", "~> 0.66.0"
23
+ end
@@ -0,0 +1,26 @@
1
+ module CheckoutSdk
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ def self.configuration
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def self.reset
11
+ @configuration = Configuration.new
12
+ end
13
+
14
+ def self.configure
15
+ yield(configuration)
16
+ end
17
+ end
18
+
19
+ require "checkout_sdk/configuration"
20
+ require "checkout_sdk/api_resource"
21
+ require "checkout_sdk/data/capture_payment"
22
+ require "checkout_sdk/data/payment_request_source"
23
+ require "checkout_sdk/data/payment_source"
24
+ require "checkout_sdk/data/refund_payment"
25
+ require "checkout_sdk/data/request_token"
26
+ require "checkout_sdk/data/void_payment"
@@ -0,0 +1,60 @@
1
+ require "excon"
2
+ require "multi_json"
3
+
4
+ class CheckoutSdk::ApiResource
5
+ attr_reader :checkout_connection
6
+
7
+ def initialize
8
+ @checkout_connection = Excon.new("#{CheckoutSdk.configuration.base_url}", persistent: true)
9
+ end
10
+
11
+ def request_payments(data_object)
12
+ post_request("/payments", data_object.data)
13
+ end
14
+
15
+ def capture_payment(data_object)
16
+ post_request("/payments/#{data_object.id}/captures", data_object.data)
17
+ end
18
+
19
+ def refund_payment(data_object)
20
+ post_request("/payments/#{data_object.id}/refunds", data_object.data)
21
+ end
22
+
23
+ def void_payment(data_object)
24
+ post_request("/payments/#{data_object.id}/voids", data_object.data)
25
+ end
26
+
27
+ def add_payment_source(data_object)
28
+ post_request("/sources", data_object.data)
29
+ end
30
+
31
+ def request_token(data_object)
32
+ post_request("/tokens", data_object.data)
33
+ end
34
+
35
+ def get_payment_details(id)
36
+ get("/payments/#{id}")
37
+ end
38
+
39
+ def get_payment_actions(id)
40
+ get("/payments/#{id}/actions")
41
+ end
42
+
43
+ private
44
+
45
+ def post_request(path, data_object)
46
+ checkout_connection.post(
47
+ path: path,
48
+ body: MultiJson.dump(data_object),
49
+ headers: { "Content-Type" => "application/json",
50
+ "Authorization" => "#{CheckoutSdk.configuration.secret_key}" }
51
+ )
52
+ end
53
+
54
+ def get(path)
55
+ checkout_connection.get(
56
+ path: path,
57
+ headers: { "Authorization" => "#{CheckoutSdk.configuration.secret_key}" }
58
+ )
59
+ end
60
+ end
@@ -0,0 +1,9 @@
1
+ class CheckoutSdk::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 CheckoutSdk::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 CheckoutSdk::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 CheckoutSdk::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 CheckoutSdk::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 CheckoutSdk::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 CheckoutSdk::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 CheckoutSdk
2
+ VERSION = "0.1.3"
3
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CheckoutSdk::ApiResource do
4
+ let(:api_resource) { CheckoutSdk::ApiResource.new }
5
+
6
+ it "has the expected connection configuration" do
7
+ expect(api_resource.checkout_connection.data[:host]).to eql("test.com")
8
+ end
9
+
10
+ describe "#request_payments" do
11
+ let(:payment_request_source) { CheckoutSdk::PaymentRequestSource.new }
12
+ let(:data) { { mock: true } }
13
+
14
+ it "sends a POST request with correct params" do
15
+ allow(payment_request_source).to receive(:data).and_return(data)
16
+
17
+ expect(api_resource.checkout_connection).to receive(:post)
18
+ .with({ body:"{\"mock\":true}",
19
+ headers:{"Authorization"=>"sk_test", "Content-Type"=>"application/json"},
20
+ path:"/payments" })
21
+
22
+ api_resource.request_payments(payment_request_source)
23
+ end
24
+ end
25
+
26
+ describe "#capture_payment" do
27
+ let(:capture_payment) { CheckoutSdk::CapturePayment.new }
28
+
29
+ it "sends a POST request with correct params" do
30
+ capture_payment.id = 1
31
+
32
+ expect(api_resource.checkout_connection).to receive(:post)
33
+ .with({ body:"{\"amount\":null,\"reference\":null,\"metadata\":null}",
34
+ headers:{"Authorization"=>"sk_test", "Content-Type"=>"application/json"},
35
+ path:"/payments/1/captures" })
36
+
37
+ api_resource.capture_payment(capture_payment)
38
+ end
39
+ end
40
+
41
+ describe "#refund_payment" do
42
+ let(:refund_payment) { CheckoutSdk::RefundPayment.new }
43
+
44
+ it "sends a POST request with correct params" do
45
+ refund_payment.id = 1
46
+
47
+ expect(api_resource.checkout_connection).to receive(:post)
48
+ .with({ body:"{\"amount\":null,\"reference\":null,\"metadata\":null}",
49
+ headers:{"Authorization"=>"sk_test", "Content-Type"=>"application/json"},
50
+ path:"/payments/1/refunds" })
51
+
52
+ api_resource.refund_payment(refund_payment)
53
+ end
54
+ end
55
+
56
+ describe "#void_payment" do
57
+ let(:void_payment) { CheckoutSdk::VoidPayment.new }
58
+
59
+ it "sends a POST request with correct params" do
60
+ void_payment.id = 1
61
+
62
+ expect(api_resource.checkout_connection).to receive(:post)
63
+ .with({ body:"{\"reference\":null,\"metadata\":null}",
64
+ headers:{"Authorization"=>"sk_test", "Content-Type"=>"application/json"},
65
+ path:"/payments/1/voids" })
66
+
67
+ api_resource.void_payment(void_payment)
68
+ end
69
+ end
70
+
71
+ describe "#add_payment_source" do
72
+ let(:payment_source) { CheckoutSdk::PaymentSource.new }
73
+ let(:data) { { mock: true } }
74
+
75
+ it "sends a POST request with correct params" do
76
+ allow(payment_source).to receive(:data).and_return(data)
77
+
78
+ expect(api_resource.checkout_connection).to receive(:post)
79
+ .with({ body:"{\"mock\":true}",
80
+ headers:{"Authorization"=>"sk_test", "Content-Type"=>"application/json"},
81
+ path:"/sources" })
82
+
83
+ api_resource.add_payment_source(payment_source)
84
+ end
85
+ end
86
+
87
+ describe "#request_token" do
88
+ let(:request_token) { CheckoutSdk::RequestToken.new }
89
+ let(:data) { { mock: true } }
90
+
91
+ it "sends a POST request with correct params" do
92
+ allow(request_token).to receive(:data).and_return(data)
93
+
94
+ expect(api_resource.checkout_connection).to receive(:post)
95
+ .with({ body:"{\"mock\":true}",
96
+ headers:{"Authorization"=>"sk_test", "Content-Type"=>"application/json"},
97
+ path:"/tokens" })
98
+
99
+ api_resource.request_token(request_token)
100
+ end
101
+ end
102
+
103
+ describe "#get_payment_details" do
104
+ let(:payment_id) { "pay_id" }
105
+
106
+ it "sends a Get request with correct params" do
107
+ expect(api_resource.checkout_connection).to receive(:get)
108
+ .with({headers: {"Authorization"=>"sk_test"},
109
+ path: "/payments/#{payment_id}"})
110
+
111
+ api_resource.get_payment_details(payment_id)
112
+ end
113
+ end
114
+
115
+ describe "#get_payment_actions" do
116
+ let(:payment_id) { "pay_id" }
117
+
118
+ it "sends a Get request with correct params" do
119
+ expect(api_resource.checkout_connection).to receive(:get)
120
+ .with({headers: {"Authorization"=>"sk_test"},
121
+ path: "/payments/#{payment_id}/actions"})
122
+
123
+ api_resource.get_payment_actions(payment_id)
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CheckoutSdk::PaymentRequestSource do
4
+ let(:payment_request_source) { CheckoutSdk::PaymentRequestSource.new }
5
+ let(:type) { "card" }
6
+ let(:card_number) { "4242424242424242" }
7
+ let(:card_expiry_month) { 6 }
8
+ let(:card_expiry_year) { 25 }
9
+ let(:card_name) { "Elmo and Friends" }
10
+ let(:card_cvv) { "123" }
11
+ let(:card_stored) { false }
12
+ let(:billing_address_line1) { "Sesame street 1" }
13
+ let(:billing_address_line2) { "" }
14
+ let(:billing_city) { "Sesame city" }
15
+ let(:billing_state) { "Sesame state" }
16
+ let(:billing_zip) { "12345" }
17
+ let(:billing_country) { "Sesame country" }
18
+ let(:phone_country_code) { "+1" }
19
+ let(:phone_number) { "415 555 2671" }
20
+ let(:id) { "12345678" }
21
+ let(:cvv) { "123" }
22
+ let(:token) { "tok_4gzeau5o2uqubbk6fufs3m7p54" }
23
+ let(:customer_id) { "12345678" }
24
+ let(:customer_email) { "elmo@friends.sesame" }
25
+ let(:expected_card_source) {
26
+ {
27
+ type: type,
28
+ number: card_number,
29
+ expiry_month: card_expiry_month,
30
+ expiry_year: card_expiry_year,
31
+ name: card_name,
32
+ cvv: card_cvv,
33
+ stored: card_stored,
34
+ billing_address: {
35
+ address_line1: billing_address_line1,
36
+ address_line2: billing_address_line2,
37
+ city: billing_city,
38
+ state: billing_state,
39
+ zip: billing_zip,
40
+ country: billing_country
41
+ },
42
+ phone: {
43
+ country_code: phone_country_code,
44
+ number: phone_number
45
+ },
46
+ }
47
+ }
48
+ let(:expected_id_source) {
49
+ {
50
+ type: type,
51
+ id: id,
52
+ cvv: cvv
53
+ }
54
+ }
55
+ let(:expected_token_source) {
56
+ {
57
+ type: type,
58
+ token: token,
59
+ billing_address: {
60
+ address_line1: billing_address_line1,
61
+ address_line2: billing_address_line2,
62
+ city: billing_city,
63
+ state: billing_state,
64
+ zip: billing_zip,
65
+ country: billing_country
66
+ },
67
+ phone: {
68
+ country_code: phone_country_code,
69
+ number: phone_number
70
+ },
71
+ }
72
+ }
73
+ let(:expected_customer_source) {
74
+ {
75
+ type: type,
76
+ id: customer_id,
77
+ email: customer_email
78
+ }
79
+ }
80
+
81
+ def get_keys(hash)
82
+ hash.map do |k, v|
83
+ v = v.first if v.is_a?(Array);
84
+
85
+ if v.is_a?(Hash)
86
+ [k, get_keys(v)]
87
+ else
88
+ k
89
+ end
90
+ end
91
+ end
92
+
93
+ describe "#data" do
94
+ context "card" do
95
+ it "uses card settings" do
96
+ payment_request_source.type = "card"
97
+
98
+ expect(get_keys(payment_request_source.data[:source])).to eql(get_keys(expected_card_source))
99
+ end
100
+ end
101
+
102
+ context "id" do
103
+ it "uses id settings" do
104
+ payment_request_source.type = "id"
105
+
106
+ expect(get_keys(payment_request_source.data[:source])).to eql(get_keys(expected_id_source))
107
+ end
108
+ end
109
+
110
+ context "token" do
111
+ it "uses token settings" do
112
+ payment_request_source.type = "token"
113
+
114
+ expect(get_keys(payment_request_source.data[:source])).to eql(get_keys(expected_token_source))
115
+ end
116
+ end
117
+
118
+ context "token" do
119
+ it "uses customer settings" do
120
+ payment_request_source.type = "customer"
121
+
122
+ expect(get_keys(payment_request_source.data[:source])).to eql(get_keys(expected_customer_source))
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CheckoutSdk::RequestToken do
4
+ let(:type) { "card" }
5
+ let(:request_token) { CheckoutSdk::RequestToken.new }
6
+ let(:token_data_version) { "EC_v1" }
7
+ let(:token_data_data) { "Base64" }
8
+ let(:token_data_signature) { "Signature" }
9
+ let(:token_data_header) { "" }
10
+ let(:token_data_signature) { }
11
+ let(:token_data_protocolVersion) { "ECv0" }
12
+ let(:token_data_signedMessage) { "signedMessage" }
13
+ let(:card_number) { "4242424242424242" }
14
+ let(:card_expiry_month) { 6 }
15
+ let(:card_expiry_year) { 25 }
16
+ let(:card_name) { "Elmo and Friends" }
17
+ let(:card_cvv) { "123" }
18
+ let(:billing_address_line1) { "Sesame street 1" }
19
+ let(:billing_address_line2) { "" }
20
+ let(:billing_city) { "Sesame city" }
21
+ let(:billing_state) { "Sesame state" }
22
+ let(:billing_zip) { "12345" }
23
+ let(:billing_country) { "Sesame country" }
24
+ let(:phone_country_code) { "+1" }
25
+ let(:phone_number) { "415 555 2671" }
26
+ let(:applepay_type) {
27
+ {
28
+ type: type,
29
+ token_data: {
30
+ version: token_data_version,
31
+ data: token_data_data,
32
+ signature: token_data_signature,
33
+ header: token_data_header
34
+ }
35
+ }
36
+ }
37
+ let(:googlepay_type) {
38
+ {
39
+ type: type,
40
+ token_data: {
41
+ signature: token_data_signature,
42
+ protocolVersion: token_data_protocolVersion,
43
+ signedMessage: token_data_signedMessage
44
+ }
45
+ }
46
+ }
47
+ let(:card_type) {
48
+ {
49
+ type: type,
50
+ number: card_number,
51
+ expiry_month: card_expiry_month,
52
+ expiry_year: card_expiry_year,
53
+ name: card_name,
54
+ cvv: card_cvv,
55
+ billing_address: {
56
+ address_line1: billing_address_line1,
57
+ address_line2: billing_address_line2,
58
+ city: billing_city,
59
+ state: billing_state,
60
+ zip: billing_zip,
61
+ country: billing_country
62
+ },
63
+ phone: {
64
+ country_code: phone_country_code,
65
+ number: phone_number
66
+ }
67
+ }
68
+ }
69
+
70
+ def get_keys(hash)
71
+ hash.map do |k, v|
72
+ v = v.first if v.is_a?(Array);
73
+
74
+ if v.is_a?(Hash)
75
+ [k, get_keys(v)]
76
+ else
77
+ k
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "#data" do
83
+ context "card" do
84
+ it "uses card settings" do
85
+ request_token.type = "card"
86
+
87
+ expect(get_keys(request_token.data)).to eql(get_keys(card_type))
88
+ end
89
+ end
90
+
91
+ context "googlepay" do
92
+ it "uses card settings" do
93
+ request_token.type = "googlepay"
94
+
95
+ expect(get_keys(request_token.data)).to eql(get_keys(googlepay_type))
96
+ end
97
+ end
98
+
99
+ context "applepay" do
100
+ it "uses card settings" do
101
+ request_token.type = "applepay"
102
+
103
+ expect(get_keys(request_token.data)).to eql(get_keys(applepay_type))
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CheckoutSdk do
4
+ it "has a version number" do
5
+ expect(CheckoutSdk::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ require "bundler/setup"
2
+ require "checkout_sdk/data/payment_request_source"
3
+ require "checkout_sdk/data/capture_payment"
4
+ require "checkout_sdk/data/refund_payment"
5
+ require "checkout_sdk/data/void_payment"
6
+ require "checkout_sdk/data/payment_source"
7
+ require "checkout_sdk/data/request_token"
8
+ require "checkout_sdk/api_resource"
9
+ require "checkout_sdk"
10
+ require "pry"
11
+
12
+
13
+ RSpec.configure do |config|
14
+ # Enable flags like --only-failures and --next-failure
15
+ config.example_status_persistence_file_path = ".rspec_status"
16
+
17
+ # Disable RSpec exposing methods globally on `Module` and `main`
18
+ config.disable_monkey_patching!
19
+
20
+ config.expect_with :rspec do |c|
21
+ c.syntax = :expect
22
+ end
23
+
24
+ # CheckoutSdk configuration
25
+ config.before(:all) do
26
+ CheckoutSdk.configure do |config|
27
+ config.secret_key = "sk_test"
28
+ config.public_key = "pk_test"
29
+ config.base_url = "https://test.com"
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkout_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Khalid Jazaerly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-02 00:00:00.000000000 Z
11
+ date: 2019-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,37 +56,76 @@ dependencies:
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.11.3
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.11.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: multi_json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: excon
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ">="
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0'
89
+ version: 0.66.0
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ">="
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0'
96
+ version: 0.66.0
83
97
  description: A Ruby API wrapper for checkout.com.
84
98
  email:
85
99
  - khalid.jaz@gmail.com
86
100
  executables: []
87
101
  extensions: []
88
102
  extra_rdoc_files: []
89
- files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - checkout_sdk.gemspec
114
+ - lib/checkout_sdk.rb
115
+ - lib/checkout_sdk/api_resource.rb
116
+ - lib/checkout_sdk/configuration.rb
117
+ - lib/checkout_sdk/data/capture_payment.rb
118
+ - lib/checkout_sdk/data/payment_request_source.rb
119
+ - lib/checkout_sdk/data/payment_source.rb
120
+ - lib/checkout_sdk/data/refund_payment.rb
121
+ - lib/checkout_sdk/data/request_token.rb
122
+ - lib/checkout_sdk/data/void_payment.rb
123
+ - lib/checkout_sdk/version.rb
124
+ - spec/checkout_sdk/api_resource_spec.rb
125
+ - spec/checkout_sdk/data/payment_request_source_spec.rb
126
+ - spec/checkout_sdk/data/request_token_spec.rb
127
+ - spec/checkout_sdk_spec.rb
128
+ - spec/spec_helper.rb
90
129
  homepage: http://checkout.com
91
130
  licenses: []
92
131
  metadata: {}
@@ -105,8 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
144
  - !ruby/object:Gem::Version
106
145
  version: '0'
107
146
  requirements: []
108
- rubyforge_project:
109
- rubygems_version: 2.5.2.3
147
+ rubygems_version: 3.0.6
110
148
  signing_key:
111
149
  specification_version: 4
112
150
  summary: A Ruby API wrapper for checkout.com.