Skip to content

Commit

Permalink
Add Klarna Payment Context Support
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-rodriguez-cko committed Apr 24, 2024
1 parent 21e48fe commit 03f750b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
10 changes: 6 additions & 4 deletions spec/checkout_sdk/payments/contexts/contexts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

module ContextsHelper

def create_payment_contexts
def create_payment_contexts_paypal
request = {
'source' => {
'type' => 'paypal'
},
'amount' => 2000,
'amount' => 1000,
'currency' => CheckoutSdk::Common::Currency::EUR,
'payment_type' => CheckoutSdk::Payments::PaymentType::REGULAR,
'capture' => true,
Expand All @@ -17,15 +17,17 @@ def create_payment_contexts
'items' => [
{
'name' => 'mask',
'unit_price' => 2000,
'quantity' => 1
'unit_price' => 1000,
'quantity' => 1,
'total_amount' => 1000
}
]
}

response = default_sdk.contexts.create_payment_contexts(request)
expect(response).not_to be nil
expect(response.id).not_to be nil
expect(response.partner_metadata.order_id).not_to be nil
response
end

Expand Down
46 changes: 40 additions & 6 deletions spec/checkout_sdk/payments/contexts/contexts_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,50 @@
include ContextsHelper

before(:all) do
@payment_context = create_payment_contexts
@payment_context_paypal = create_payment_contexts_paypal
end

describe '.create_payment_contexts' do
context 'when creating a payment contexts with valid data' do
it { is_valid_payment_context @payment_context }
context 'when creating a payment contexts paypal with valid data' do
it { is_valid_payment_context @payment_context_paypal }
end
context 'when creating a payment contexts klarna with valid data' do
it 'raises an error (apm_service_unavailable)' do
request = {
'source' => {
'type' => 'klarna',
'account_holder' => {
'billing_address' => {
'country' => 'DE'
}
}
},
'amount' => 1000,
'currency' => CheckoutSdk::Common::Currency::EUR,
'payment_type' => CheckoutSdk::Payments::PaymentType::REGULAR,
'processing_channel_id' => ENV.fetch('CHECKOUT_PROCESSING_CHANNEL_ID', nil),
'items' => [
{
'name' => 'mask',
'unit_price' => 1000,
'quantity' => 1,
'total_amount' => 1000,
'reference' => 'BA67A'
}
],
'processing' => {
'locale' => 'en-GB'
}
}
expect { default_sdk.contexts.create_payment_contexts(request) }
.to raise_error(CheckoutSdk::CheckoutApiException) { |e| expect(e.error_details[:error_codes].first).to eq 'apm_service_unavailable' }
end
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 }
it { is_valid_payment_context_details default_sdk.contexts.get_payment_context_details @payment_context_paypal.id }
end
end
end
Expand All @@ -27,11 +59,13 @@ def is_valid_payment_context(payment_context)
end

def is_valid_payment_context_details(payment_context_details_response)
assert_response payment_context_details_response, %w[payment_request
assert_response payment_context_details_response, %w[status
payment_request
payment_request.source
payment_request.source.type
payment_request.amount
payment_request.currency
payment_request.payment_type
payment_request.capture
payment_request.items
payment_request.success_url
payment_request.failure_url
Expand Down

0 comments on commit 03f750b

Please sign in to comment.