Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds request and get
payment contexts
endpoints (#129)
- Loading branch information
1 parent
9f65b92
commit 83d2bd5
Showing
13 changed files
with
125 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
lib/checkout_sdk/payments/contexts/payment_contexts_client.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module CheckoutSdk | ||
module Payments | ||
class PaymentContextsClient < Client | ||
PAYMENT_CONTEXTS = 'payment-contexts' | ||
|
||
# @param [ApiClient] api_client | ||
# @param [CheckoutConfiguration] configuration | ||
def initialize(api_client, configuration) | ||
super api_client, configuration, CheckoutSdk::AuthorizationType::SECRET_KEY_OR_OAUTH | ||
end | ||
|
||
# @param [Hash] payment_contexts | ||
def create_payment_contexts(payment_contexts) | ||
api_client.invoke_post(PAYMENT_CONTEXTS, sdk_authorization, payment_contexts) | ||
end | ||
|
||
# @param [String] payment_context_id | ||
def get_payment_context_details(payment_context_id) | ||
api_client.invoke_get(build_path(PAYMENT_CONTEXTS, payment_context_id), sdk_authorization) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module ContextsHelper | ||
|
||
def create_payment_contexts | ||
request = { | ||
'source' => { | ||
'type' => 'paypal' | ||
}, | ||
'amount' => 2000, | ||
'currency' => CheckoutSdk::Common::Currency::EUR, | ||
'payment_type' => CheckoutSdk::Payments::PaymentType::REGULAR, | ||
'capture' => true, | ||
'processing_channel_id' => ENV.fetch('CHECKOUT_PROCESSING_CHANNEL_ID', nil), | ||
'success_url' => 'https://example.com/payments/success', | ||
'failure_url' => 'https://example.com/payments/fail', | ||
'items' => [ | ||
{ | ||
'name' => 'mask', | ||
'unit_price' => 2000, | ||
'quantity' => 1 | ||
} | ||
] | ||
} | ||
|
||
response = default_sdk.contexts.create_payment_contexts(request) | ||
expect(response).not_to be nil | ||
expect(response.id).not_to be nil | ||
response | ||
end | ||
|
||
end |
51 changes: 51 additions & 0 deletions
51
spec/checkout_sdk/payments/contexts/contexts_integration_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe CheckoutSdk::Payments do | ||
include ContextsHelper | ||
|
||
before(:all) do | ||
@payment_context = create_payment_contexts | ||
end | ||
|
||
describe '.create_payment_contexts' do | ||
context 'when creating a payment contexts with valid data' do | ||
it { is_valid_payment_context @payment_context } | ||
end | ||
end | ||
|
||
describe '.get_payment_context_details' do | ||
context 'when retrieving existing payment context details' do | ||
it { is_valid_payment_context_details default_sdk.contexts.get_payment_context_details @payment_context.id } | ||
end | ||
end | ||
end | ||
|
||
def is_valid_payment_context(payment_context) | ||
assert_response payment_context, %w[id | ||
partner_metadata | ||
partner_metadata.order_id] | ||
end | ||
|
||
def is_valid_payment_context_details(payment_context_details_response) | ||
assert_response payment_context_details_response, %w[payment_request | ||
payment_request.amount | ||
payment_request.currency | ||
payment_request.payment_type | ||
payment_request.capture | ||
payment_request.items | ||
payment_request.success_url | ||
payment_request.failure_url | ||
partner_metadata | ||
partner_metadata.order_id] | ||
|
||
expect(payment_context_details_response.payment_request.amount).to eq 2000 | ||
expect(payment_context_details_response.payment_request.currency).to eq CheckoutSdk::Common::Currency::EUR | ||
expect(payment_context_details_response.payment_request.payment_type).to eq CheckoutSdk::Payments::PaymentType::REGULAR | ||
expect(payment_context_details_response.payment_request.capture).to eq true | ||
expect(payment_context_details_response.payment_request.items[0].name).to eq 'mask' | ||
expect(payment_context_details_response.payment_request.items[0].unit_price).to eq 2000 | ||
expect(payment_context_details_response.payment_request.items[0].quantity).to eq 1 | ||
expect(payment_context_details_response.payment_request.success_url).to eq 'https://example.com/payments/success' | ||
expect(payment_context_details_response.payment_request.failure_url).to eq 'https://example.com/payments/fail' | ||
expect(payment_context_details_response.partner_metadata.order_id).not_to be_nil | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters