checkout_sdk 0.1.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +20 -20
- data/LICENSE +21 -0
- data/README.md +122 -35
- data/checkout_sdk.gemspec +4 -3
- data/documentation/.gitignore +20 -0
- data/documentation/docs/environment.md +26 -0
- data/documentation/docs/getting_started.md +48 -0
- data/documentation/docs/initialize.md +19 -0
- data/documentation/docs/install.md +21 -0
- data/documentation/docs/payments.md +200 -0
- data/documentation/docs/sources.md +53 -0
- data/documentation/docs/tokens.md +88 -0
- data/documentation/docusaurus.config.js +60 -0
- data/documentation/package-lock.json +13511 -0
- data/documentation/package.json +32 -0
- data/documentation/sidebars.js +10 -0
- data/documentation/src/css/custom.css +103 -0
- data/documentation/src/pages/index.js +10 -0
- data/documentation/src/pages/styles.module.css +37 -0
- data/documentation/static/img/favicon.png +0 -0
- data/documentation/static/img/logo.png +0 -0
- data/documentation/static/img/undraw_docusaurus_mountain.svg +170 -0
- data/documentation/static/img/undraw_docusaurus_react.svg +169 -0
- data/documentation/static/img/undraw_docusaurus_tree.svg +1 -0
- data/documentation/yarn.lock +9369 -0
- data/lib/checkout_sdk/api_resource.rb +23 -6
- data/lib/checkout_sdk/configuration.rb +2 -1
- data/lib/checkout_sdk/data/payment_request_source.rb +2 -1
- data/lib/checkout_sdk/version.rb +1 -1
- data/spec/checkout_sdk/api_resource_spec.rb +8 -8
- data/spec/checkout_sdk_spec.rb +14 -0
- metadata +41 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26f117e315cedf6293b15fabeca2736d00a5e59a98257e0f6af6c111e1d4ca7b
|
4
|
+
data.tar.gz: 17935194ff3650b305c3f2795c6932cb61a2b07e84259683397785367bb4d8fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e76a36a2f4ffabace3f0911192b63eeda2119ee39bc0b1fad7792afdd81222b6e6a3acc42f85d2209510cb15fbe5893988e88c69c65dc51cf171824f74fbb14c
|
7
|
+
data.tar.gz: 36767831e67555237bf1f2f8ed28ff861693bd32737c3b7f5d7f0a1579a2ba8c53e7280ad13cfa02937a48f2e5dd80a1fe06a1fdf8986f17736c1c050d94f2c5
|
data/Gemfile.lock
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
checkout_sdk (0.
|
5
|
-
excon (
|
4
|
+
checkout_sdk (0.3.2)
|
5
|
+
excon (>= 0.66, <= 0.88.0)
|
6
6
|
multi_json (~> 1.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
coderay (1.1.
|
12
|
-
diff-lcs (1.
|
13
|
-
excon (0.
|
11
|
+
coderay (1.1.3)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
excon (0.88.0)
|
14
14
|
method_source (0.9.2)
|
15
|
-
multi_json (1.
|
15
|
+
multi_json (1.15.0)
|
16
16
|
pry (0.11.3)
|
17
17
|
coderay (~> 1.1.0)
|
18
18
|
method_source (~> 0.9.0)
|
19
19
|
rake (10.5.0)
|
20
|
-
rspec (3.
|
21
|
-
rspec-core (~> 3.
|
22
|
-
rspec-expectations (~> 3.
|
23
|
-
rspec-mocks (~> 3.
|
24
|
-
rspec-core (3.
|
25
|
-
rspec-support (~> 3.
|
26
|
-
rspec-expectations (3.
|
20
|
+
rspec (3.10.0)
|
21
|
+
rspec-core (~> 3.10.0)
|
22
|
+
rspec-expectations (~> 3.10.0)
|
23
|
+
rspec-mocks (~> 3.10.0)
|
24
|
+
rspec-core (3.10.1)
|
25
|
+
rspec-support (~> 3.10.0)
|
26
|
+
rspec-expectations (3.10.1)
|
27
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-mocks (3.
|
28
|
+
rspec-support (~> 3.10.0)
|
29
|
+
rspec-mocks (3.10.2)
|
30
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
-
rspec-support (~> 3.
|
32
|
-
rspec-support (3.
|
31
|
+
rspec-support (~> 3.10.0)
|
32
|
+
rspec-support (3.10.2)
|
33
33
|
|
34
34
|
PLATFORMS
|
35
35
|
ruby
|
36
36
|
|
37
37
|
DEPENDENCIES
|
38
|
-
bundler (~>
|
38
|
+
bundler (~> 2.0)
|
39
39
|
checkout_sdk!
|
40
40
|
pry (~> 0.11.3)
|
41
41
|
rake (~> 10.0)
|
42
|
-
rspec (~> 3.
|
42
|
+
rspec (~> 3.5)
|
43
43
|
|
44
44
|
BUNDLED WITH
|
45
|
-
|
45
|
+
2.2.31
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Checkout.com
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
[![GitHub license](https://img.shields.io/github/license/checkout/checkout-sdk-ruby.svg)](https://github.com/checkout/checkout-sdk-ruby/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/checkout/checkout-sdk-ruby.svg)](https://GitHub.com/checkout/checkout-sdk-ruby/releases/)
|
2
2
|
|
3
|
-
|
3
|
+
<p align="center"><img src="https://i.ibb.co/5Mx7ZsS/Screenshot-2020-07-30-at-17-20-31.png" width="20%"></p>
|
4
4
|
|
5
|
-
|
5
|
+
# Checkout.com Ruby SDK
|
6
|
+
|
7
|
+
# :rocket: Install
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
@@ -12,13 +14,17 @@ gem 'checkout_sdk'
|
|
12
14
|
|
13
15
|
And then execute:
|
14
16
|
|
15
|
-
|
17
|
+
```bash
|
18
|
+
$ bundle
|
19
|
+
```
|
16
20
|
|
17
21
|
Or install it yourself as:
|
18
22
|
|
19
|
-
|
23
|
+
```bash
|
24
|
+
$ gem install checkout_sdk
|
25
|
+
```
|
20
26
|
|
21
|
-
|
27
|
+
# :wrench: Configure
|
22
28
|
|
23
29
|
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
30
|
|
@@ -27,37 +33,118 @@ CheckoutSdk.configure do |config|
|
|
27
33
|
config.secret_key = ENV['SECRET_KEY']
|
28
34
|
config.public_key = ENV['PUBLIC_KEY']
|
29
35
|
config.base_url = ENV['BASE_URL']
|
36
|
+
config.persistent = true|false # default: true
|
30
37
|
end
|
31
38
|
```
|
32
39
|
|
33
|
-
|
40
|
+
# :book: Documentation
|
41
|
+
|
42
|
+
You can see the [SDK documentation here](https://checkout.github.io/checkout-sdk-ruby/getting_started/).
|
43
|
+
|
44
|
+
# :dash: Quickstart
|
45
|
+
|
46
|
+
#### Source Type: `token`
|
47
|
+
A card token can be obtained using one of Checkout.com's JavaScript frontend solutions such as [Frames](https://docs.checkout.com/docs/frames "Frames") or any of the [mobile SDKs](https://docs.checkout.com/docs/sdks#section-mobile-sdk-libraries "Mobile SDKs")
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
payment_request_source = CheckoutSdk::PaymentRequestSource.new
|
51
|
+
payment_request_source.type = "token"
|
52
|
+
payment_request_source.token = "tok_..."
|
53
|
+
payment_request_source.amount = 2022
|
54
|
+
payment_request_source.currency = "GBP"
|
55
|
+
|
56
|
+
api_resource = CheckoutSdk::ApiResource.new
|
57
|
+
|
58
|
+
# Send API call
|
59
|
+
response = api_resource.request_payment(payment_request_source)
|
60
|
+
|
61
|
+
# response parsing
|
62
|
+
response.data # => {...}
|
63
|
+
response.body # => "..."
|
64
|
+
response.headers # => {...}
|
65
|
+
response.remote_ip # => "..."
|
66
|
+
response.status # => 200
|
67
|
+
response.remote_ip # => "..."
|
68
|
+
response.local_port # => 51601
|
69
|
+
response.local_address # => "..."
|
70
|
+
```
|
71
|
+
|
72
|
+
#### Source Type: `id`
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
payment_request_source = CheckoutSdk::PaymentRequestSource.new
|
76
|
+
payment_request_source.type = "id"
|
77
|
+
payment_request_source.token = "src_..."
|
78
|
+
payment_request_source.amount = 2022
|
79
|
+
payment_request_source.currency = "GBP"
|
80
|
+
|
81
|
+
api_resource = CheckoutSdk::ApiResource.new
|
82
|
+
|
83
|
+
# Send API call
|
84
|
+
response = api_resource.request_payment(payment_request_source)
|
85
|
+
|
86
|
+
# response parsing
|
87
|
+
response.data # => {...}
|
88
|
+
response.body # => "..."
|
89
|
+
response.headers # => {...}
|
90
|
+
response.remote_ip # => "..."
|
91
|
+
response.status # => 200
|
92
|
+
response.remote_ip # => "..."
|
93
|
+
response.local_port # => 51601
|
94
|
+
response.local_address # => "..."
|
95
|
+
```
|
96
|
+
|
34
97
|
|
98
|
+
#### Source Type: `card`
|
99
|
+
[Fully PCI Compliant](https://docs.checkout.com/docs/pci-compliance) merchants only
|
35
100
|
```ruby
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
101
|
+
payment_request_source = CheckoutSdk::PaymentRequestSource.new
|
102
|
+
payment_request_source.type = "card"
|
103
|
+
payment_request_source.card_number = "4242424242424242"
|
104
|
+
payment_request_source.card_expiry_month = 6
|
105
|
+
payment_request_source.card_expiry_year = 2025
|
106
|
+
payment_request_source.card_name = "Bruce Wayne"
|
107
|
+
payment_request_source.card_cvv = "100"
|
108
|
+
payment_request_source.amount = 2022
|
109
|
+
payment_request_source.currency = "GBP"
|
110
|
+
|
111
|
+
api_resource = CheckoutSdk::ApiResource.new
|
112
|
+
|
113
|
+
# Send API call
|
114
|
+
response = api_resource.request_payment(payment_request_source)
|
115
|
+
|
116
|
+
# response parsing
|
117
|
+
response.data # => {...}
|
118
|
+
response.body # => "..."
|
119
|
+
response.headers # => {...}
|
120
|
+
response.remote_ip # => "..."
|
121
|
+
response.status # => 200
|
122
|
+
response.remote_ip # => "..."
|
123
|
+
response.local_port # => 51601
|
124
|
+
response.local_address # => "..."
|
125
|
+
```
|
126
|
+
|
127
|
+
# :warning: Boolean/falsy values
|
128
|
+
|
129
|
+
"nil" or empty strings will be stripped from API calls
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
# ignored
|
133
|
+
payment_request_source.capture = nil
|
134
|
+
payment_request_source.capture = ""
|
135
|
+
```
|
136
|
+
|
137
|
+
but "false" or 0 are retained and sent in the request
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
# sent
|
141
|
+
payment_request_source.capture = false
|
142
|
+
payment_request_source.capture = 0
|
143
|
+
```
|
144
|
+
See [api_resource_spec](https://github.com/checkout/checkout-sdk-ruby/blob/master/spec/checkout_sdk/api_resource_spec.rb#L10-L24) for details.
|
145
|
+
|
146
|
+
# :rotating_light: Tests
|
147
|
+
|
148
|
+
```bash
|
149
|
+
$ rspec
|
150
|
+
```
|
data/checkout_sdk.gemspec
CHANGED
@@ -13,11 +13,12 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "http://checkout.com"
|
14
14
|
spec.files = `git ls-files`.split("\n")
|
15
15
|
spec.require_paths = ["lib"]
|
16
|
+
spec.license = "MIT"
|
16
17
|
|
17
|
-
spec.add_development_dependency "bundler", "~>
|
18
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
18
19
|
spec.add_development_dependency "rake", "~> 10.0"
|
19
|
-
spec.add_development_dependency "rspec", "~> 3.
|
20
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
20
21
|
spec.add_development_dependency "pry", "~> 0.11.3"
|
21
22
|
spec.add_dependency "multi_json", '~> 1.0'
|
22
|
-
spec.add_dependency "excon", "
|
23
|
+
spec.add_dependency "excon", ">= 0.66", "<= 0.88.0"
|
23
24
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Dependencies
|
2
|
+
/node_modules
|
3
|
+
|
4
|
+
# Production
|
5
|
+
/build
|
6
|
+
|
7
|
+
# Generated files
|
8
|
+
.docusaurus
|
9
|
+
.cache-loader
|
10
|
+
|
11
|
+
# Misc
|
12
|
+
.DS_Store
|
13
|
+
.env.local
|
14
|
+
.env.development.local
|
15
|
+
.env.test.local
|
16
|
+
.env.production.local
|
17
|
+
|
18
|
+
npm-debug.log*
|
19
|
+
yarn-debug.log*
|
20
|
+
yarn-error.log*
|
@@ -0,0 +1,26 @@
|
|
1
|
+
---
|
2
|
+
id: environment
|
3
|
+
title: Environment
|
4
|
+
---
|
5
|
+
|
6
|
+
The SDK will target an environment based on the **base_url** value you provide when you initialize it:
|
7
|
+
|
8
|
+
**Sandbox**: https://api.sandbox.checkout.com
|
9
|
+
|
10
|
+
**Live**: https://api.checkout.com
|
11
|
+
|
12
|
+
:::caution
|
13
|
+
|
14
|
+
Public and secret key pairs will only work for their relevant environment. Sandbox keys begin with "pk_test_" or "sk_test_". You will receive separate Live keys for use in your production environment when going live with Checkout.com.
|
15
|
+
|
16
|
+
:::
|
17
|
+
|
18
|
+
## Testing
|
19
|
+
|
20
|
+
If you are testing in the Sandbox environment, Checkout.com provides a list of [test card details](https://docs.checkout.com/testing/test-card-numbers). You can also simulate a lot of edge cases like Declines, by using [special transaction values](https://docs.checkout.com/testing/response-code-testing).
|
21
|
+
|
22
|
+
:::note
|
23
|
+
|
24
|
+
You can also test 3D Secure with the test cards provided. If you want to test 3DS 2 flows, use the cards mentioned [here](https://docs.checkout.com/testing/3d-secure-testing).
|
25
|
+
|
26
|
+
:::
|
@@ -0,0 +1,48 @@
|
|
1
|
+
---
|
2
|
+
id: getting_started
|
3
|
+
title: Getting Started
|
4
|
+
sidebar_label: Getting Started
|
5
|
+
---
|
6
|
+
|
7
|
+
The Checkout.com Ruby SDK makes it easy to interact with the Unified Payments API. You can easily accept card payments and manage these using the same integration.
|
8
|
+
|
9
|
+
[![GitHub license](https://img.shields.io/github/license/checkout/checkout-sdk-ruby.svg)](https://github.com/checkout/checkout-sdk-ruby/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/checkout/checkout-sdk-ruby.svg)](https://GitHub.com/checkout/checkout-sdk-ruby/releases/)
|
10
|
+
|
11
|
+
## Get a test account
|
12
|
+
|
13
|
+
If you are starting the integration process, and you want to start interacting with Checkout.com's API, you will need a test account, so you can get your API keys.
|
14
|
+
|
15
|
+
export const RedirectButton = ({text, link}) => (
|
16
|
+
<a
|
17
|
+
href={link}
|
18
|
+
target="\_blank"
|
19
|
+
className="get-test-account">{text}</a>
|
20
|
+
);
|
21
|
+
|
22
|
+
<RedirectButton text="Get a test account" link="https://www.checkout.com/get-test-account" />
|
23
|
+
|
24
|
+
## Authentication
|
25
|
+
|
26
|
+
export const Highlight = ({children, color}) => (
|
27
|
+
<span
|
28
|
+
style={{
|
29
|
+
backgroundColor: color,
|
30
|
+
borderRadius: '2px',
|
31
|
+
color: '#fff',
|
32
|
+
padding: '0.2rem',
|
33
|
+
}}>
|
34
|
+
{children}
|
35
|
+
</span>
|
36
|
+
);
|
37
|
+
|
38
|
+
When you sign up for an account, you are given a secret and public API key pair. They will be used to initialise the SDK. You can find the keys by navigating to <Highlight color="#1877F2">Settings > Channels > API keys</Highlight> in Checkout.com's Hub.
|
39
|
+
|
40
|
+
:::warning
|
41
|
+
|
42
|
+
Never share your secret keys. Keep them guarded and secure.
|
43
|
+
|
44
|
+
:::
|
45
|
+
|
46
|
+
## Payload and Responses
|
47
|
+
|
48
|
+
If you want to see all the parameters that you can provide in API requests, as well as examples of possible responses, please follow the Checkout.com [API Reference](https://api-reference.checkout.com/).
|
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
id: initialize
|
3
|
+
title: Initialize
|
4
|
+
---
|
5
|
+
|
6
|
+
## Configuration
|
7
|
+
|
8
|
+
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.
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
CheckoutSdk.configure do |config|
|
12
|
+
config.secret_key = "your secret key"
|
13
|
+
config.public_key = "your public key"
|
14
|
+
config.base_url = "https://api.sandbox.checkout.com" #for sandbox
|
15
|
+
end
|
16
|
+
|
17
|
+
api_resource = CheckoutSdk::ApiResource.new
|
18
|
+
```
|
19
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
id: install
|
3
|
+
title: Install
|
4
|
+
---
|
5
|
+
|
6
|
+
## Add to your application's Gemfile
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'checkout_sdk'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
```bash
|
14
|
+
$ bundle
|
15
|
+
```
|
16
|
+
|
17
|
+
## Or install yourself
|
18
|
+
|
19
|
+
```bash
|
20
|
+
$ gem install checkout_sdk
|
21
|
+
```
|
@@ -0,0 +1,200 @@
|
|
1
|
+
---
|
2
|
+
id: payments
|
3
|
+
title: Payments
|
4
|
+
---
|
5
|
+
|
6
|
+
You can find a list of request body parameters and possible outcomes [here](https://api-reference.checkout.com/#tag/Payments).
|
7
|
+
|
8
|
+
export const Highlight = ({children, color}) => (
|
9
|
+
<span
|
10
|
+
style={{
|
11
|
+
color: color,
|
12
|
+
padding: '0.2rem',
|
13
|
+
}}>
|
14
|
+
{children}
|
15
|
+
</span>
|
16
|
+
);
|
17
|
+
|
18
|
+
:::important
|
19
|
+
|
20
|
+
#### Using boolean/falsy values
|
21
|
+
|
22
|
+
"nil" or empty strings will be stripped from API calls
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# ignored
|
26
|
+
payment_request_source.capture = nil
|
27
|
+
payment_request_source.capture = ""
|
28
|
+
```
|
29
|
+
|
30
|
+
but "false" or 0 are retained and sent in the request
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# sent
|
34
|
+
payment_request_source.capture = false
|
35
|
+
payment_request_source.capture = 0
|
36
|
+
```
|
37
|
+
See [api_resource_spec](https://github.com/checkout/checkout-sdk-ruby/blob/master/spec/checkout_sdk/api_resource_spec.rb#L10-L24) for details.
|
38
|
+
|
39
|
+
:::
|
40
|
+
|
41
|
+
## Request a card payment with a <Highlight color="#25c2a0">card token</Highlight>
|
42
|
+
|
43
|
+
The card token is generated by front-end integration options such as [Frames](https://docs.checkout.com/docs/frames) or one of the [Mobile SDKs](https://docs.checkout.com/docs/sdks#section-mobile-sdk-libraries). Keep in mind that this token expires in 15 minutes and can only be used once.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
payment_request_source = CheckoutSdk::PaymentRequestSource.new
|
47
|
+
payment_request_source.type = "token"
|
48
|
+
payment_request_source.token = "tok_ubfj2q76miwundwlk72vxt2i7q"
|
49
|
+
payment_request_source.amount = 1000
|
50
|
+
payment_request_source.currency = "GBP"
|
51
|
+
payment_request_source.reference = "ORD-090857"
|
52
|
+
|
53
|
+
# Send API call
|
54
|
+
response = api_resource.request_payment(payment_request_source)
|
55
|
+
|
56
|
+
# response parsing
|
57
|
+
puts(response.data) # => {...}
|
58
|
+
puts(response.body) # => "..."
|
59
|
+
```
|
60
|
+
|
61
|
+
## Request a card payment with a <Highlight color="#25c2a0">full card details</Highlight>
|
62
|
+
|
63
|
+
:::warning
|
64
|
+
|
65
|
+
You need to have a high level of PCI Compliance (SAQ-D) to be able to send requests with full card details. Note that unless this payment option is enabled on your account by Checkout.com, the <Highlight color="#5A522C">request will fail</Highlight>. Contact you account manager to request access for this payment interaction.
|
66
|
+
|
67
|
+
:::
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
payment_request_source = CheckoutSdk::PaymentRequestSource.new
|
71
|
+
payment_request_source.type = "card"
|
72
|
+
payment_request_source.card_number = "4242424242424242"
|
73
|
+
payment_request_source.card_expiry_month = 6
|
74
|
+
payment_request_source.card_expiry_year = 2025
|
75
|
+
payment_request_source.card_name = "Bruce Wayne"
|
76
|
+
payment_request_source.card_cvv = "100"
|
77
|
+
payment_request_source.amount = 1000
|
78
|
+
payment_request_source.currency = "GBP"
|
79
|
+
|
80
|
+
# Send API call
|
81
|
+
response = api_resource.request_payment(payment_request_source)
|
82
|
+
|
83
|
+
# response parsing
|
84
|
+
puts(response.data) # => {...}
|
85
|
+
puts(response.body) # => "..."
|
86
|
+
```
|
87
|
+
|
88
|
+
## Request a card payment with a <Highlight color="#25c2a0">an existing card</Highlight>
|
89
|
+
|
90
|
+
After you perform at least one successful payment for a customer, Checkout.com will return a <Highlight color="#02b48f">source.id</Highlight>. This id does not expire, so it can be used to perform subsequent payments without needing the customer to enter the card details again.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
payment_request_source = CheckoutSdk::PaymentRequestSource.new
|
94
|
+
payment_request_source.type = "id"
|
95
|
+
payment_request_source.token = "src_vg3tm54ndfbefotjlmgrrvbxli"
|
96
|
+
payment_request_source.amount = 1000
|
97
|
+
payment_request_source.currency = "GBP"
|
98
|
+
|
99
|
+
# Send API call
|
100
|
+
response = api_resource.request_payment(payment_request_source)
|
101
|
+
|
102
|
+
# response parsing
|
103
|
+
puts(response.data) # => {...}
|
104
|
+
puts(response.body) # => "..."
|
105
|
+
```
|
106
|
+
|
107
|
+
## Request a <Highlight color="#25c2a0">3D Secure payment</Highlight>
|
108
|
+
|
109
|
+
You have the ability to authenticate with 3DS in a payment request. The request body is similar to normal card payments, but with some additional parameters. [Read more about 3DS](https://docs.checkout.com/docs/3d-secure-payments)
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
payment_request_source = CheckoutSdk::PaymentRequestSource.new
|
113
|
+
payment_request_source.type = "token"
|
114
|
+
payment_request_source.token = "tok_ubfj2q76miwundwlk72vxt2i7q"
|
115
|
+
payment_request_source.amount = 1000
|
116
|
+
payment_request_source.currency = "GBP"
|
117
|
+
payment_request_source.reference = "ORD-090857"
|
118
|
+
payment_request_source.threeds_enabled = true
|
119
|
+
|
120
|
+
# Send API call
|
121
|
+
response = api_resource.request_payment(payment_request_source)
|
122
|
+
|
123
|
+
# response parsing
|
124
|
+
puts(response.data) # => {...}
|
125
|
+
puts(response.body) # => "..."
|
126
|
+
```
|
127
|
+
|
128
|
+
3D Secure payments will return a redirection URL. Here is an example of a 3DS response:
|
129
|
+
|
130
|
+
```json
|
131
|
+
{
|
132
|
+
"id": "pay_hehfmlkpykeupofyxf7nbr6yyy",
|
133
|
+
"status": "Pending",
|
134
|
+
"customer": {
|
135
|
+
"id": "cus_u4a4zosnrw7ehhzr7jipbkdzo4"
|
136
|
+
},
|
137
|
+
"3ds": {
|
138
|
+
"downgraded": false,
|
139
|
+
"enrolled": "Y"
|
140
|
+
},
|
141
|
+
"_links": {
|
142
|
+
"self": {
|
143
|
+
"href": "https://api.sandbox.checkout.com/payments/pay_hehfmlkpykeupofyxf7nbr6yyy"
|
144
|
+
},
|
145
|
+
"redirect": {
|
146
|
+
"href": "https://sandbox.checkout.com/api2/v2/3ds/acs/sid_feixbit6us3utfedjulm6egnsu"
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
150
|
+
```
|
151
|
+
|
152
|
+
You can access the redirection URL via the SDK like so:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
redirectURL = response.data._links.redirect.href
|
156
|
+
```
|
157
|
+
|
158
|
+
## Get payment details
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
details = api_resource.get_payment_details("pay_juevt3h5mcjulir2t5g3wfug6u") # or with session id sid_XXX
|
162
|
+
```
|
163
|
+
|
164
|
+
## Get payment actions
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
actions = api_resource.get_payment_actions("pay_juevt3h5mcjulir2t5g3wfug6u")
|
168
|
+
```
|
169
|
+
|
170
|
+
## Capture a payment
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
capture_payment = CheckoutSdk::CapturePayment.new
|
174
|
+
capture_payment.id = "pay_y3oqhf46pyzuxjbcn2giaqnb44"
|
175
|
+
capture_payment.amount = "1000"
|
176
|
+
capture_payment.reference = "your reference"
|
177
|
+
|
178
|
+
response = api_resource.capture_payment(capture_payment)
|
179
|
+
```
|
180
|
+
|
181
|
+
## Refund a payment
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
refund_payment = CheckoutSdk::RefundPayment.new
|
185
|
+
refund_payment.id = "pay_y3oqhf46pyzuxjbcn2giaqnb44"
|
186
|
+
refund_payment.amount = "1000"
|
187
|
+
refund_payment.reference = "your reference"
|
188
|
+
|
189
|
+
response = api_resource.refund_payment(refund_payment)
|
190
|
+
```
|
191
|
+
|
192
|
+
## Void a payment
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
void_payment = CheckoutSdk::VoidPayment.new
|
196
|
+
void_payment.id = "pay_y3oqhf46pyzuxjbcn2giaqnb44"
|
197
|
+
void_payment.reference = "your reference"
|
198
|
+
|
199
|
+
response = api_resource.void_payment(void_payment)
|
200
|
+
```
|