-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea42e02
commit 68e2d8d
Showing
8 changed files
with
185 additions
and
91 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
20 changes: 20 additions & 0 deletions
20
lib/checkout_sdk/payments/sessions/payment_sessions_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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module CheckoutSdk | ||
module Payments | ||
class PaymentSessionsClient < Client | ||
PAYMENT_SESSIONS = 'payment-sessions' | ||
|
||
# @param [ApiClient] api_client | ||
# @param [CheckoutConfiguration] configuration | ||
def initialize(api_client, configuration) | ||
super api_client, configuration, CheckoutSdk::AuthorizationType::SECRET_KEY | ||
end | ||
|
||
# @param [Hash] payment_sessions | ||
def create_payment_sessions(payment_sessions) | ||
api_client.invoke_post(PAYMENT_SESSIONS, sdk_authorization, payment_sessions) | ||
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
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,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module PaymentSessionsHelper | ||
|
||
def create_payment_sessions | ||
request = { | ||
'amount' => 2000, | ||
'currency' => CheckoutSdk::Common::Currency::GBP, | ||
'reference' => 'ORD-123A', | ||
'billing' => { | ||
'address' => { | ||
'country' => CheckoutSdk::Common::Country::GB | ||
} | ||
}, | ||
'customer' => { | ||
'name' => 'John Smith', | ||
'email' => '[email protected]', | ||
}, | ||
'success_url' => 'https://example.com/payments/success', | ||
'failure_url' => 'https://example.com/payments/fail' | ||
} | ||
|
||
response = default_sdk.payment_sessions.create_payment_sessions(request) | ||
expect(response).not_to be nil | ||
|
||
response | ||
end | ||
|
||
end |
31 changes: 31 additions & 0 deletions
31
spec/checkout_sdk/payments/sessions/sessions_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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe CheckoutSdk::Payments do | ||
include PaymentSessionsHelper | ||
|
||
before(:all) do | ||
@payment_sessions = create_payment_sessions | ||
end | ||
|
||
describe '.create_payment_sessions' do | ||
context 'when creating a payment sessions with valid data' do | ||
it { is_valid_payment_sessions @payment_sessions } | ||
end | ||
end | ||
end | ||
|
||
def is_valid_payment_sessions(payment_sessions) | ||
assert_response payment_sessions, %w[id | ||
amount | ||
locale | ||
currency | ||
payment_methods | ||
_links | ||
_links.self] | ||
|
||
expect(payment_sessions.id).not_to be nil | ||
expect(payment_sessions.amount).to eq 2000 | ||
expect(payment_sessions.locale).to eq 'en-GB' | ||
expect(payment_sessions.currency).to eq CheckoutSdk::Common::Currency::GBP | ||
expect(payment_sessions.payment_methods).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