-
Notifications
You must be signed in to change notification settings - Fork 14
/
payment_links_integration_spec.rb
101 lines (87 loc) · 3.64 KB
/
payment_links_integration_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
RSpec.describe CheckoutSdk::Payments::PaymentsLinksClient do
describe '.create_payment_link' do
context 'when creating a payment link with valid parameters' do
it 'creates payment link correctly' do
request = create_payment_links_request
response = default_sdk.links.create_payment_link request
assert_response response, %w[id
reference
expires_on
warnings
_links
http_metadata]
expect(response.http_metadata.status_code).to eq 201
end
end
end
describe '.get_payment_link' do
subject(:link) { default_sdk.links.create_payment_link create_payment_links_request }
context 'when fetching an existing payment link' do
it 'retrieves payment link details' do
response = default_sdk.links.get_payment_link link.id
assert_response response, %w[id
status
amount
currency
reference
description
customer
billing
products
_links
http_metadata]
expect(response.http_metadata.status_code).to eq 200
expect(response.id).to eq link.id
end
end
context 'when fetching inexistant payment link' do
it 'raises an error (404 - not_found)' do
expect { default_sdk.links.get_payment_link 'not_found' }
.to raise_error(CheckoutSdk::CheckoutApiException) { |e| expect(e.http_metadata.status_code).to eq 404 }
end
end
end
end
def create_payment_links_request
billing_information = CheckoutSdk::Payments::BillingInformation.new
billing_information.address = address
billing_information.phone = phone
shipping_details = CheckoutSdk::Payments::ShippingDetails.new
shipping_details.address = address
shipping_details.phone = phone
product = CheckoutSdk::Common::Product.new
product.name = 'Gold Necklace'
product.quantity = 1
product.price = 200
three_ds_request = CheckoutSdk::Payments::ThreeDSRequest.new
three_ds_request.enabled = true
three_ds_request.attempt_n3d = false
processing_settings = CheckoutSdk::Payments::ProcessingSettings.new
processing_settings.aft = true
risk_request = CheckoutSdk::Payments::RiskRequest.new
risk_request.enabled = true
billing_descriptor = CheckoutSdk::Payments::BillingDescriptor.new
billing_descriptor.city = 'London'
billing_descriptor.name = 'Awesome name'
billing_descriptor.reference = 'another reference'
request = CheckoutSdk::Payments::PaymentLink.new
request.amount = 200
request.reference = 'reference'
request.currency = CheckoutSdk::Common::Currency::GBP
request.description = 'Payment for Gold Necklace'
request.customer = common_customer_request
request.shipping = shipping_details
request.billing = billing_information
request.recipient = payment_recipient
request.processing = processing_settings
request.products = [product]
request.risk = risk_request
request.return_url = 'https://example.com/payments/return'
request.locale = 'en-GB'
request.three_ds = three_ds_request
request.expires_in = 6400
request.capture = true
request.allow_payment_methods = [CheckoutSdk::Common::PaymentSourceType::CARD,
CheckoutSdk::Common::PaymentSourceType::IDEAL]
request
end