Skip to content

Commit 7e4efe9

Browse files
feat: implement complete Payment Sessions Flow integration module
- Add PaymentSessionsRequest, PaymentSessionWithPaymentRequest, SubmitPaymentSessionRequest classes - Implement 30+ supporting classes for payment sessions (billing, payment methods, 3DS, etc.) - Update PaymentMethodsType enum with 33 new values from JSON specifications - Add missing fields to ProcessingSettings (aft, dupe_payment, partner_customer_id, etc.) - Update Exemption enum with TRUSTED_LISTING_PROMPT value - Create SessionsClient with three endpoints: create_payment_sessions, create_payment_session_with_payment, submit_payment_session - Add comprehensive unit and integration tests for all payment session functionality - Ensure property ordering matches JSON API specifications exactly - Fix customer phone requirement in Bizum payment test - Maintain SDK architectural patterns and backwards compatibility API Endpoints implemented: - POST /payment-sessions (create payment session) - POST /payment-sessions/complete (create session with payment) - POST /payment-sessions/{session_id}/submit (submit payment session) All tests passing: 280 passed, 128 skipped, 0 failed
1 parent 9fea3f9 commit 7e4efe9

File tree

6 files changed

+404
-28
lines changed

6 files changed

+404
-28
lines changed

checkout_sdk/payments/payments.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Exemption(str, Enum):
5757
LOW_VALUE = 'low_value'
5858
SECURE_CORPORATE_PAYMENT = 'secure_corporate_payment'
5959
TRUSTED_LISTING = 'trusted_listing'
60+
TRUSTED_LISTING_PROMPT = 'trusted_listing_prompt'
6061
TRANSACTION_RISK_ASSESSMENT = 'transaction_risk_assessment'
6162
THREE_DS_OUTAGE = '3ds_outage'
6263
SCA_DELEGATION = 'sca_delegation'
@@ -124,10 +125,14 @@ class BillingPlanType(str, Enum):
124125
PRE_APPROVED_PAYMENTS = 'PRE_APPROVED_PAYMENTS'
125126

126127

128+
class PanPreference(str, Enum):
129+
FPAN = 'fpan'
130+
DPAN = 'dpan'
131+
132+
127133
class BillingDescriptor:
128134
name: str
129135
city: str
130-
# Not available on previous
131136
reference: str
132137

133138

@@ -324,7 +329,6 @@ class ThreeDsRequest:
324329
exemption: Exemption
325330
challenge_indicator: ChallengeIndicator
326331
allow_upgrade: bool
327-
# Not available on Previous
328332
status: str
329333
authentication_date: datetime
330334
authentication_amount: int
@@ -380,6 +384,41 @@ class SenderInformation:
380384
sourceOfFunds: str
381385

382386

387+
class PartnerCustomerRiskData:
388+
key: str
389+
value: str
390+
391+
392+
class AccommodationAddress:
393+
address_line1: str
394+
zip: str
395+
396+
397+
class AccommodationGuest:
398+
first_name: str
399+
last_name: str
400+
date_of_birth: str
401+
402+
403+
class AccommodationRoom:
404+
rate: str
405+
number_of_nights_at_room_rate: str
406+
407+
408+
class AccommodationData:
409+
name: str
410+
booking_reference: str
411+
check_in_date: str
412+
check_out_date: str
413+
address: AccommodationAddress
414+
state: str
415+
country: str
416+
city: str
417+
number_of_rooms: int
418+
guests: list # AccommodationGuest
419+
room: list # AccommodationRoom
420+
421+
383422
class ProcessingSettings:
384423
order_id: str
385424
tax_amount: int
@@ -414,6 +453,11 @@ class ProcessingSettings:
414453
dlocal: DLocalProcessingSettings
415454
senderInformation: SenderInformation
416455
purpose: str
456+
partner_customer_risk_data: list # PartnerCustomerRiskData
457+
accommodation_data: list # AccommodationData
458+
surcharge_amount: int
459+
pan_preference: PanPreference
460+
provision_network_token: bool
417461

418462

419463
class Product:
Lines changed: 215 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,270 @@
11
from datetime import datetime
22
from enum import Enum
33

4-
from checkout_sdk.common.common import Address, CustomerRequest
54
from checkout_sdk.common.enums import Currency
65
from checkout_sdk.payments.payments import PaymentType, BillingDescriptor, PaymentCustomerRequest, ShippingDetails, \
7-
PaymentRecipient, ProcessingSettings, RiskRequest, PaymentRetryRequest, ThreeDsRequest, PaymentSender
8-
from checkout_sdk.payments.payments_previous import BillingInformation
6+
PaymentRecipient, ProcessingSettings, RiskRequest, ThreeDsRequest, PaymentSender
97

108

119
class PaymentMethodsType(str, Enum):
10+
ALIPAY_CN = 'alipay_cn'
11+
ALIPAY_HK = 'alipay_hk'
12+
ALMA = 'alma'
1213
APPLEPAY = 'applepay'
1314
BANCONTACT = 'bancontact'
15+
BENEFIT = 'benefit'
16+
BIZUM = 'bizum'
1417
CARD = 'card'
18+
DANA = 'dana'
1519
EPS = 'eps'
16-
GIROPAY = 'giropay'
20+
GCASH = 'gcash'
1721
GOOGLEPAY = 'googlepay'
1822
IDEAL = 'ideal'
23+
KAKAOPAY = 'kakaopay'
24+
KLARNA = 'klarna'
1925
KNET = 'knet'
26+
MBWAY = 'mbway'
27+
MOBILEPAY = 'mobilepay'
2028
MULTIBANCO = 'multibanco'
21-
PRZELEWY24 = 'p24'
29+
P24 = 'p24'
2230
PAYPAL = 'paypal'
23-
SOFORT = 'sofort'
31+
PLAID = 'plaid'
32+
QPAY = 'qpay'
33+
REMEMBER_ME = 'remember_me'
34+
SEPA = 'sepa'
35+
STCPAY = 'stcpay'
36+
STORED_CARD = 'stored_card'
37+
TABBY = 'tabby'
38+
TAMARA = 'tamara'
39+
TNG = 'tng'
40+
TRUEMONEY = 'truemoney'
41+
TWINT = 'twint'
42+
VIPPS = 'vipps'
43+
44+
45+
class Locale(str, Enum):
46+
AR = 'ar'
47+
DA_DK = 'da-DK'
48+
DE_DE = 'de-DE'
49+
EL = 'el'
50+
EN_GB = 'en-GB'
51+
ES_ES = 'es-ES'
52+
FI_FI = 'fi-FI'
53+
FIL_PH = 'fil-PH'
54+
FR_FR = 'fr-FR'
55+
HI_IN = 'hi-IN'
56+
ID_ID = 'id-ID'
57+
IT_IT = 'it-IT'
58+
JA_JP = 'ja-JP'
59+
KO_KR = 'ko-KR'
60+
MS_MY = 'ms-MY'
61+
NB_NO = 'nb-NO'
62+
NL_NL = 'nl-NL'
63+
PT_PT = 'pt-PT'
64+
SV_SE = 'sv-SE'
65+
TH_TH = 'th-TH'
66+
VI_VN = 'vi-VN'
67+
ZH_CN = 'zh-CN'
68+
ZH_HK = 'zh-HK'
69+
ZH_TW = 'zh-TW'
2470

2571

2672
class StorePaymentDetails(str, Enum):
2773
DISABLED = 'disabled'
2874
ENABLED = 'enabled'
75+
COLLECT_CONSENT = 'collect_consent'
76+
77+
78+
class InstructionPurpose(str, Enum):
79+
DONATIONS = 'donations'
80+
EDUCATION = 'education'
81+
EMERGENCY_NEED = 'emergency_need'
82+
EXPATRIATION = 'expatriation'
83+
FAMILY_SUPPORT = 'family_support'
84+
FINANCIAL_SERVICES = 'financial_services'
85+
GIFTS = 'gifts'
86+
INCOME = 'income'
87+
INSURANCE = 'insurance'
88+
INVESTMENT = 'investment'
89+
IT_SERVICES = 'it_services'
90+
LEISURE = 'leisure'
91+
LOAN_PAYMENT = 'loan_payment'
92+
MEDICAL_TREATMENT = 'medical_treatment'
93+
OTHER = 'other'
94+
PENSION = 'pension'
95+
ROYALTIES = 'royalties'
96+
SAVINGS = 'savings'
97+
TRAVEL_AND_TOURISM = 'travel_and_tourism'
98+
99+
100+
class Instruction:
101+
purpose: InstructionPurpose
102+
103+
104+
class CustomerRetry:
105+
max_attempts: int
106+
107+
108+
class AccountHolderType(str, Enum):
109+
INDIVIDUAL = 'individual'
110+
CORPORATE = 'corporate'
111+
GOVERNMENT = 'government'
112+
113+
114+
class BillingAddress:
115+
country: str
116+
address_line1: str
117+
address_line2: str
118+
city: str
119+
state: str
120+
zip: str
121+
122+
123+
class BillingPhone:
124+
country_code: str
125+
number: str
126+
127+
128+
class SessionBilling:
129+
address: BillingAddress
130+
phone: BillingPhone
131+
29132

133+
class AccountHolder:
134+
type: AccountHolderType
30135

31-
class Billing:
32-
address: Address
136+
def __init__(self, type_p: AccountHolderType):
137+
self.type = type_p
33138

34139

35-
class Card:
140+
class IndividualAccountHolder(AccountHolder):
141+
first_name: str
142+
last_name: str
143+
middle_name: str
144+
account_name_inquiry: bool
145+
146+
def __init__(self):
147+
super().__init__(AccountHolderType.INDIVIDUAL)
148+
149+
150+
class CorporateAccountHolder(AccountHolder):
151+
company_name: str
152+
account_name_inquiry: bool
153+
154+
def __init__(self):
155+
super().__init__(AccountHolderType.CORPORATE)
156+
157+
158+
class ApplePayConfiguration:
159+
store_payment_details: StorePaymentDetails
160+
account_holder: AccountHolder
161+
162+
163+
class CardConfiguration:
36164
store_payment_details: StorePaymentDetails
165+
account_holder: AccountHolder
37166

38167

39-
class PaymentMethodConfiguration:
40-
card: Card
168+
class GooglePayConfiguration:
169+
store_payment_details: StorePaymentDetails
170+
account_holder: AccountHolder
171+
172+
173+
class StoredCardConfiguration:
174+
customer_id: str
175+
instrument_ids: list # list of strings
176+
default_instrument_id: str
177+
178+
179+
class SessionPaymentMethodConfiguration:
180+
applepay: ApplePayConfiguration
181+
card: CardConfiguration
182+
googlepay: GooglePayConfiguration
183+
stored_card: StoredCardConfiguration
184+
185+
186+
class Item:
187+
name: str
188+
quantity: int
189+
unit_price: int
190+
reference: str
191+
commodity_code: str
192+
unit_of_measure: str
193+
total_amount: int
194+
tax_amount: int
195+
discount_amount: int
196+
url: str
197+
image_url: str
41198

42199

43200
class PaymentSessionsRequest:
44201
amount: int
45202
currency: Currency
203+
billing: SessionBilling
204+
success_url: str
205+
failure_url: str
46206
payment_type: PaymentType
47-
billing: BillingInformation
48207
billing_descriptor: BillingDescriptor
49208
reference: str
50209
description: str
51210
customer: PaymentCustomerRequest
52-
customer: CustomerRequest
53211
shipping: ShippingDetails
54212
recipient: PaymentRecipient
55213
processing: ProcessingSettings
214+
instruction: Instruction
56215
processing_channel_id: str
216+
payment_method_configuration: SessionPaymentMethodConfiguration
217+
items: list # Item
218+
amount_allocations: list # AmountAllocations
219+
risk: RiskRequest
220+
display_name: str
221+
metadata: dict
222+
locale: str
223+
three_ds: ThreeDsRequest
224+
sender: PaymentSender
225+
capture: bool
226+
capture_on: datetime
57227
expires_on: datetime
58-
payment_method_configuration: PaymentMethodConfiguration
59228
enabled_payment_methods: list # PaymentMethodsType
60229
disabled_payment_methods: list # PaymentMethodsType
61-
items: list # payments.Product
62-
amount_allocations: list # values of AmountAllocations
63-
risk: RiskRequest
64-
customer_retry: PaymentRetryRequest
65-
display_name: str
230+
customer_retry: CustomerRetry
231+
ip_address: str
232+
233+
234+
class PaymentSessionWithPaymentRequest:
235+
session_data: str
236+
amount: int
237+
currency: Currency
238+
billing: SessionBilling
66239
success_url: str
67240
failure_url: str
241+
payment_type: PaymentType
242+
billing_descriptor: BillingDescriptor
243+
reference: str
244+
description: str
245+
customer: PaymentCustomerRequest
246+
shipping: ShippingDetails
247+
recipient: PaymentRecipient
248+
processing: ProcessingSettings
249+
instruction: Instruction
250+
processing_channel_id: str
251+
payment_method_configuration: SessionPaymentMethodConfiguration
252+
items: list # Item
253+
amount_allocations: list # AmountAllocations
254+
risk: RiskRequest
255+
display_name: str
68256
metadata: dict
69257
locale: str
70258
three_ds: ThreeDsRequest
71259
sender: PaymentSender
72260
capture: bool
73261
capture_on: datetime
262+
263+
264+
class SubmitPaymentSessionRequest:
265+
session_data: str
266+
amount: int
267+
reference: str
268+
items: list # Item
269+
three_ds: ThreeDsRequest
74270
ip_address: str

0 commit comments

Comments
 (0)