Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions craftgate/model/apm_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class ApmType(str, Enum):
SODEXO_GIFT = "SODEXO_GIFT"
EDENRED = "EDENRED"
EDENRED_GIFT = "EDENRED_GIFT"
TOKENFLEX = "TOKENFLEX"
TOKENFLEX_GIFT = "TOKENFLEX_GIFT"
PAYPAL = "PAYPAL"
KLARNA = "KLARNA"
AFTERPAY = "AFTERPAY"
Expand Down
2 changes: 2 additions & 0 deletions craftgate/model/payment_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class PaymentMethod(str, Enum):
PAYONEER = "PAYONEER"
SODEXO = "SODEXO"
SODEXO_GIFT = "SODEXO_GIFT"
TOKENFLEX = "TOKENFLEX"
TOKENFLEX_GIFT = "TOKENFLEX_GIFT"
EDENRED = "EDENRED"
EDENRED_GIFT = "EDENRED_GIFT"
ALIPAY = "ALIPAY"
Expand Down
1 change: 1 addition & 0 deletions craftgate/model/payment_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class PaymentProvider(str, Enum):
PAYONEER = "PAYONEER"
SODEXO = "SODEXO"
EDENRED = "EDENRED"
TOKENFLEX = "TOKENFLEX"
INSTANT_TRANSFER = "INSTANT_TRANSFER"
ALIPAY = "ALIPAY"
PAYPAL = "PAYPAL"
Expand Down
76 changes: 76 additions & 0 deletions tests/test_payment_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,82 @@ def test_complete_edenred_apm_payment(self):
self.assertIsNotNone(getattr(resp, "payment_id", None))
self.assertEqual(PaymentStatus.SUCCESS, resp.payment_status)

def test_init_tokenflex_apm_payment(self):
items = []
for name, price in [("item 1", "0.60"), ("item 2", "0.40")]:
pi = PaymentItem()
pi.name = name
pi.external_id = str(uuid.uuid4())
pi.price = Decimal(price)
items.append(pi)

req = InitApmPaymentRequest()
req.apm_type = ApmType.TOKENFLEX
req.price = Decimal("1")
req.paid_price = Decimal("1")
req.currency = Currency.TRY
req.payment_group = PaymentGroup.LISTING_OR_SUBSCRIPTION
req.conversation_id = "456d1297-908e-4bd6-a13b-4be31a6e47d5"
req.external_id = "optional-externalId"
req.callback_url = "https://www.your-website.com/craftgate-apm-callback"
req.additional_params = {"paymentCode": "123456"}
req.items = items

resp = self.payment.init_apm_payment(req)
print(resp)
self.assertIsNotNone(getattr(resp, "payment_id", None))
self.assertIsNone(getattr(resp, "redirect_url", None))
self.assertEqual(PaymentStatus.WAITING, resp.payment_status)
self.assertEqual(ApmAdditionalAction.OTP_REQUIRED, resp.additional_action)

def test_complete_tokenflex_apm_payment(self):
req = CompleteApmPaymentRequest()
req.payment_id = 1
req.additional_params = {"otpCode": "784294"}

resp = self.payment.complete_apm_payment(req)
print(resp)
self.assertIsNotNone(getattr(resp, "payment_id", None))
self.assertEqual(PaymentStatus.SUCCESS, resp.payment_status)

def test_init_tokenflex_gift_apm_payment(self):
items = []
for name, price in [("item 1", "0.60"), ("item 2", "0.40")]:
pi = PaymentItem()
pi.name = name
pi.external_id = str(uuid.uuid4())
pi.price = Decimal(price)
items.append(pi)

req = InitApmPaymentRequest()
req.apm_type = ApmType.TOKENFLEX_GIFT
req.price = Decimal("1")
req.paid_price = Decimal("1")
req.currency = Currency.TRY
req.payment_group = PaymentGroup.LISTING_OR_SUBSCRIPTION
req.conversation_id = "456d1297-908e-4bd6-a13b-4be31a6e47d5"
req.external_id = "optional-externalId"
req.callback_url = "https://www.your-website.com/craftgate-apm-callback"
req.additional_params = {"paymentCode": "123456"}
req.items = items

resp = self.payment.init_apm_payment(req)
print(resp)
self.assertIsNotNone(getattr(resp, "payment_id", None))
self.assertIsNone(getattr(resp, "redirect_url", None))
self.assertEqual(PaymentStatus.WAITING, resp.payment_status)
self.assertEqual(ApmAdditionalAction.OTP_REQUIRED, resp.additional_action)

def test_complete_tokenflex_gift_apm_payment(self):
req = CompleteApmPaymentRequest()
req.payment_id = 1
req.additional_params = {"otpCode": "784294"}

resp = self.payment.complete_apm_payment(req)
print(resp)
self.assertIsNotNone(getattr(resp, "payment_id", None))
self.assertEqual(PaymentStatus.SUCCESS, resp.payment_status)

def test_init_paypal_apm_payment(self):
items = []
for name, price in [("item 1", "0.60"), ("item 2", "0.40")]:
Expand Down