-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add-serializer-to-response-wrapper
- Loading branch information
Showing
13 changed files
with
217 additions
and
1 deletion.
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
Empty file.
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,91 @@ | ||
from datetime import datetime | ||
|
||
from checkout_sdk.common.common import Address | ||
from checkout_sdk.common.enums import Currency, PaymentSourceType | ||
from checkout_sdk.payments.payments import PaymentRequestSource, PaymentType, ShippingDetails, BillingPlan, \ | ||
ShippingPreference, UserAction | ||
|
||
|
||
class PaymentContextsPartnerCustomerRiskData: | ||
key: str | ||
value: str | ||
|
||
|
||
class PaymentContextsTicket: | ||
number: str | ||
issue_date: datetime | ||
issuing_carrier_code: str | ||
travel_package_indicator: str | ||
travel_agency_name: str | ||
travel_agency_code: str | ||
|
||
|
||
class PaymentContextsPassenger: | ||
first_name: str | ||
last_name: str | ||
date_of_birth: datetime | ||
address: Address | ||
|
||
|
||
class PaymentContextsFlightLegDetails: | ||
flight_number: str | ||
carrier_code: str | ||
class_of_travelling: str | ||
departure_airport: str | ||
departure_date: datetime | ||
departure_time: str | ||
arrival_airport: str | ||
stop_over_code: str | ||
fare_basis_code: str | ||
|
||
|
||
class PaymentContextsAirlineData: | ||
ticket: list # payment.contexts.PaymentContextsTicket | ||
passenger: list # payment.contexts.PaymentContextsPassenger | ||
flight_leg_details: list # payment.contexts.PaymentContextsFlightLegDetails | ||
|
||
|
||
class PaymentContextsProcessing: | ||
plan: BillingPlan | ||
shipping_amount: int | ||
invoice_id: str | ||
brand_name: str | ||
locale: str | ||
shipping_preference: ShippingPreference | ||
user_action: UserAction | ||
partner_customer_risk_data: PaymentContextsPartnerCustomerRiskData | ||
airline_data: list # payment.contexts.PaymentContextsAirlineData | ||
|
||
|
||
class PaymentContextsItems: | ||
name: str | ||
quantity: int | ||
unit_price: int | ||
reference: str | ||
total_amount: int | ||
tax_amount: int | ||
discount_amount: int | ||
url: str | ||
image_url: str | ||
|
||
|
||
class PaymentContextsRequest: | ||
source: PaymentRequestSource | ||
amount: int | ||
currency: Currency | ||
payment_type: PaymentType | ||
capture: bool | ||
shipping: ShippingDetails | ||
processing: PaymentContextsProcessing | ||
processing_channel_id: str | ||
reference: str | ||
description: str | ||
success_url: str | ||
failure_url: str | ||
items: list # payments.contexts.PaymentContextsItems | ||
|
||
|
||
class PaymentContextPayPalSource(PaymentRequestSource): | ||
|
||
def __init__(self): | ||
super().__init__(PaymentSourceType.PAYPAL) |
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,24 @@ | ||
from __future__ import absolute_import | ||
|
||
from checkout_sdk.api_client import ApiClient | ||
from checkout_sdk.authorization_type import AuthorizationType | ||
from checkout_sdk.checkout_configuration import CheckoutConfiguration | ||
from checkout_sdk.client import Client | ||
from checkout_sdk.payments.contexts.contexts import PaymentContextsRequest | ||
|
||
|
||
class PaymentContextsClient(Client): | ||
__PAYMENT_CONTEXTS_PATH = 'payment-contexts' | ||
|
||
def __init__(self, api_client: ApiClient, configuration: CheckoutConfiguration): | ||
super().__init__(api_client=api_client, | ||
configuration=configuration, | ||
authorization_type=AuthorizationType.SECRET_KEY_OR_OAUTH) | ||
|
||
def create_payment_contexts(self, payment_contexts_request: PaymentContextsRequest): | ||
return self._api_client.post(self.__PAYMENT_CONTEXTS_PATH, self._sdk_authorization(), | ||
payment_contexts_request) | ||
|
||
def get_payment_context_details(self, payment_context_id: str): | ||
return self._api_client.get(self.build_path(self.__PAYMENT_CONTEXTS_PATH, payment_context_id), | ||
self._sdk_authorization()) |
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 |
---|---|---|
@@ -1 +1 @@ | ||
VERSION = "3.0.16" | ||
VERSION = "3.0.17" |
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 @@ | ||
import pytest | ||
|
||
from checkout_sdk.payments.contexts.contexts import PaymentContextsRequest | ||
from checkout_sdk.payments.contexts.contexts_client import PaymentContextsClient | ||
|
||
|
||
@pytest.fixture(scope='class') | ||
def client(mock_sdk_configuration, mock_api_client): | ||
return PaymentContextsClient(api_client=mock_api_client, configuration=mock_sdk_configuration) | ||
|
||
|
||
class TestPaymentContextsClient: | ||
|
||
def test_should_create_payment_contexts(self, mocker, client: PaymentContextsClient): | ||
mocker.patch('checkout_sdk.api_client.ApiClient.post', return_value='response') | ||
assert client.create_payment_contexts(PaymentContextsRequest()) == 'response' | ||
|
||
def test_should_get_payment_context_details(self, mocker, client: PaymentContextsClient): | ||
mocker.patch('checkout_sdk.api_client.ApiClient.get', return_value='response') | ||
assert client.get_payment_context_details('payment_contexts_id') == 'response' |
58 changes: 58 additions & 0 deletions
58
tests/payments/contexts/payment_contexts_integration_test.py
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,58 @@ | ||
from __future__ import absolute_import | ||
|
||
import os | ||
|
||
from checkout_sdk.common.enums import Currency | ||
from checkout_sdk.payments.contexts.contexts import PaymentContextsRequest, PaymentContextPayPalSource, \ | ||
PaymentContextsItems | ||
from checkout_sdk.payments.payments import PaymentType | ||
from tests.checkout_test_utils import assert_response | ||
|
||
|
||
def test_should_create_and_get_payment_context_details(default_api): | ||
request = create_payment_contexts_request() | ||
|
||
response = default_api.contexts.create_payment_contexts(request) | ||
|
||
assert_response(response, | ||
'http_metadata', | ||
'id', | ||
'partner_metadata.order_id') | ||
|
||
payment_contexts_details = default_api.contexts.get_payment_context_details(response.id) | ||
|
||
assert_response(payment_contexts_details, | ||
'http_metadata', | ||
'payment_request', | ||
'payment_request.source', | ||
'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') | ||
|
||
|
||
def create_payment_contexts_request(): | ||
source = PaymentContextPayPalSource() | ||
|
||
items = PaymentContextsItems() | ||
items.name = 'mask' | ||
items.unit_price = 2000 | ||
items.quantity = 1 | ||
|
||
request = PaymentContextsRequest() | ||
request.source = source | ||
request.amount = 2000 | ||
request.currency = Currency.EUR | ||
request.payment_type = PaymentType.REGULAR | ||
request.capture = True | ||
request.processing_channel_id = os.environ.get('CHECKOUT_PROCESSING_CHANNEL_ID') | ||
request.success_url = 'https://example.com/payments/success' | ||
request.failure_url = 'https://example.com/payments/failure' | ||
request.items = [items] | ||
|
||
return request |
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