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 29, 2024
1 parent 2672d6e commit 72c66df
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
18 changes: 17 additions & 1 deletion checkout_sdk/payments/contexts/contexts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from datetime import datetime

from checkout_sdk.common.common import Address, CustomerRequest
from deprecated import deprecated

from checkout_sdk.common.common import Address, CustomerRequest, AccountHolder
from checkout_sdk.common.enums import Currency, PaymentSourceType
from checkout_sdk.payments.payments import PaymentRequestSource, PaymentType, ShippingDetails, BillingPlan, \
ShippingPreference, UserAction
Expand Down Expand Up @@ -87,7 +89,21 @@ class PaymentContextsRequest:
items: list # payments.contexts.PaymentContextsItems


@deprecated("This class will be removed in the future. Use PaymentContextPaypalSource instead")
class PaymentContextPayPalSource(PaymentRequestSource):

def __init__(self):
super().__init__(PaymentSourceType.PAYPAL)


class PaymentContextPaypalSource(PaymentRequestSource):

def __init__(self):
super().__init__(PaymentSourceType.PAYPAL)


class PaymentContextKlarnaSource(PaymentRequestSource):
account_holder: AccountHolder

def __init__(self):
super().__init__(PaymentSourceType.KLARNA)
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ flake8>=4.0.1
python-dateutil>=2.8.2
pre-commit>=2.17.0
pylint>=2.12.2
Deprecated>=1.2.14
49 changes: 42 additions & 7 deletions tests/payments/contexts/payment_contexts_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import os

from checkout_sdk.common.enums import Currency
from checkout_sdk.payments.contexts.contexts import PaymentContextsRequest, PaymentContextPayPalSource, \
PaymentContextsItems
from checkout_sdk.common.common import AccountHolder, Address
from checkout_sdk.common.enums import Currency, Country
from checkout_sdk.payments.contexts.contexts import PaymentContextsRequest, PaymentContextsItems, \
PaymentContextPaypalSource, PaymentContextKlarnaSource, PaymentContextsProcessing
from checkout_sdk.payments.payments import PaymentType
from tests.checkout_test_utils import assert_response
from tests.checkout_test_utils import assert_response, APM_SERVICE_UNAVAILABLE, check_error_item


def test_should_create_and_get_payment_context_details(default_api):
Expand Down Expand Up @@ -36,17 +37,51 @@ def test_should_create_and_get_payment_context_details(default_api):
'partner_metadata.order_id')


def test_create_payment_contexts_klarna_request(default_api):
processing = PaymentContextsProcessing()
processing.locale = "en-GB"

billing_address = Address()
billing_address.country = Country.DE

account_holder = AccountHolder()
account_holder.billing_address = billing_address

source = PaymentContextKlarnaSource()
source.account_holder = account_holder

items = PaymentContextsItems()
items.name = 'mask'
items.unit_price = 1000
items.quantity = 1
items.total_amount = 1000

request = PaymentContextsRequest()
request.source = source
request.amount = 1000
request.currency = Currency.EUR
request.payment_type = PaymentType.REGULAR
request.processing_channel_id = os.environ.get('CHECKOUT_PROCESSING_CHANNEL_ID')
request.items = [items]
request.processing = processing

check_error_item(callback=default_api.contexts.create_payment_contexts,
error_item=APM_SERVICE_UNAVAILABLE,
payment_contexts_request=request)


def create_payment_contexts_request():
source = PaymentContextPayPalSource()
source = PaymentContextPaypalSource()

items = PaymentContextsItems()
items.name = 'mask'
items.unit_price = 2000
items.unit_price = 1000
items.quantity = 1
items.total_amount = 1000

request = PaymentContextsRequest()
request.source = source
request.amount = 2000
request.amount = 1000
request.currency = Currency.EUR
request.payment_type = PaymentType.REGULAR
request.capture = True
Expand Down

0 comments on commit 72c66df

Please sign in to comment.