Skip to content

Commit

Permalink
Merge pull request #55 from cassiewang/feat/add-papi
Browse files Browse the repository at this point in the history
feat: Add payments API
  • Loading branch information
bob-xendit authored Nov 3, 2022
2 parents 44bb7cc + 16a3db1 commit 758845c
Show file tree
Hide file tree
Showing 61 changed files with 2,794 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@ cython_debug/

### End of generation

.idea/
.idea/

.DS_Store
53 changes: 53 additions & 0 deletions examples/payment_method_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import xendit

from xendit.models.paymentmethod import ewallet

from print_running_function import print_running_function


class CreatePaymentMethod:
@staticmethod
def run(xendit_instance, **kwargs):
try:
payment_method = xendit_instance.PaymentMethod.create(**kwargs)
print(payment_method)
except xendit.XenditError as e:
print("Error status code:", e.status_code)
print("Error message:", e)

@staticmethod
def example(xendit_instance):
args = {
"type": "EWALLET",
"reusability": "ONE_TIME_USE",
"ewallet": ewallet.EWallet.Query(
channel_code="PAYMAYA",
channel_properties=ewallet.ChannelProperties.Query(
success_return_url="https://mock-test.co",
failure_return_url="https://mock-test.co",
cancel_return_url="https://mock-test.co",
),
),
}
print_running_function("xendit.PaymentMethod.create", args)
CreatePaymentMethod.run(xendit_instance, **args)


def ask_payment_method_input():
print("Input the action that you want to use")
print("0. Exit")
print("1. Create Payment Method")
try:
return int(input())
except ValueError:
print("Invalid input. Please type a number")
return ask_payment_method_input()


def payment_method_example(xendit_instance):
payment_method_input = ask_payment_method_input()
while payment_method_input != 0:
if payment_method_input == 1:
print("Running example of Create Payment Method")
CreatePaymentMethod.example(xendit_instance)
payment_method_input = ask_payment_method_input()
55 changes: 55 additions & 0 deletions examples/payment_request_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import xendit

from xendit.models import ewallet, PaymentMethod

from print_running_function import print_running_function


class CreatePaymentRequest:
@staticmethod
def run(xendit_instance, **kwargs):
try:
payment_request = xendit_instance.PaymentRequest.create(**kwargs)
print(payment_request)
except xendit.XenditError as e:
print("Error status code:", e.status_code)
print("Error message:", e)

@staticmethod
def example(xendit_instance):
args = {
"amount": 1500,
"currency": "IDR",
"payment_method": PaymentMethod.Query(
type="EWALLET",
reusability="ONE_TIME_USE",
ewallet=ewallet.EWallet.Query(
channel_code="OVO",
channel_properties=ewallet.ChannelProperties.Query(
mobile_number="+628123123123"
),
),
),
}
print_running_function("xendit.PaymentRequest.create", args)
CreatePaymentRequest.run(xendit_instance, **args)


def ask_payment_method_input():
print("Input the action that you want to use")
print("0. Exit")
print("1. Create Payment Request")
try:
return int(input())
except ValueError:
print("Invalid input. Please type a number")
return ask_payment_method_input()


def payment_method_example(xendit_instance):
payment_method_input = ask_payment_method_input()
while payment_method_input != 0:
if payment_method_input == 1:
print("Running example of Create Payment Method")
CreatePaymentRequest.example(xendit_instance)
payment_method_input = ask_payment_method_input()
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "xendit-python"
version = "0.1.7"
description = "Xendit REST API Client for Python - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services https://xendit.github.io/apireference/"
version = "0.1.8"
description = "Xendit REST API Client for Python - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets, Payments API, Services https://xendit.github.io/apireference/"
authors = ["Maahir Ur Rahman <[email protected]>"]
license = "MIT"
repository = "https://github.com/xendit/xendit-python"
Expand Down
1 change: 1 addition & 0 deletions tests/integration/base_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ def assert_returned_object_has_same_key_as_sample_response(
"""
expected_key_list = [*sample_response]
actual_key_list = [*(vars(returned_object))]

assert set(expected_key_list).issubset(actual_key_list)
206 changes: 206 additions & 0 deletions tests/integration/test_payment_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
import pytest
from tests.sampleresponse.payment_method import payment_method_response
from xendit.models.paymentmethod.card.card import Card
from xendit.models.paymentmethod.card.card_information import \
CardInformation
from xendit.models.paymentmethod.card.channel_properties import \
ChannelProperties as CardChannelProperties
from xendit.models.paymentmethod.direct_debit.channel_properties import \
ChannelProperties as DirectDebitChannelProperties
from xendit.models.paymentmethod.direct_debit.direct_debit import \
DirectDebit
from xendit.models.paymentmethod.ewallet.channel_properties import \
ChannelProperties as EWalletChannelProperties
from xendit.models.paymentmethod.ewallet.ewallet import EWallet
from xendit.models.paymentmethod.over_the_counter.channel_properties import \
ChannelProperties as OTCChannelProperties
from xendit.models.paymentmethod.over_the_counter.over_the_counter import \
OverTheCounter
from xendit.models.paymentmethod.qr_code.qr_code import QRCode
from xendit.models.paymentmethod.virtual_account.channel_properties import \
ChannelProperties as VAChannelProperties
from xendit.models.paymentmethod.virtual_account.virtual_account import \
VirtualAccount

from .base_integration_test import BaseIntegrationTest


class TestPaymentMethod(BaseIntegrationTest):
@pytest.fixture
def PaymentMethod(self, xendit_instance):
return xendit_instance.PaymentMethod

def test_get_return_correct_keys(self, PaymentMethod):
payment_method = PaymentMethod.get(payment_method_id="pm-1c229762-c21a-433d-8da5-f02240387e34")
self.assert_returned_object_has_same_key_as_sample_response(
payment_method, payment_method_response()
)

def test_create_ewallet_return_correct_keys(self, PaymentMethod):
payment_method = PaymentMethod.create(
type="EWALLET",
reusability="ONE_TIME_USE",
ewallet=EWallet.Query(
channel_code="PAYMAYA",
channel_properties=EWalletChannelProperties.Query(
cancel_return_url="https://redirect.me/nostuff",
failure_return_url="https://redirect.me/badstuff",
success_return_url="https://redirect.me/goodstuff"
)
)
)

self.assert_returned_object_has_same_key_as_sample_response(
payment_method, payment_method_response()
)

def test_create_direct_debit_return_correct_keys(self, PaymentMethod):
payment_method = PaymentMethod.create(
type="DIRECT_DEBIT",
reusability="MULTIPLE_USE",
customer_id="1c320af8-5b4b-45f8-bffa-9caeacada3a1",
direct_debit=DirectDebit.Query(
channel_code="BPI",
channel_properties=DirectDebitChannelProperties.Query(
failure_return_url="https://redirect.me/badstuff",
success_return_url="https://redirect.me/goodstuff"
)
)
)

self.assert_returned_object_has_same_key_as_sample_response(
payment_method, payment_method_response()
)

def test_create_card_return_correct_keys(self, PaymentMethod):
payment_method = PaymentMethod.create(
type="CARD",
reusability="MULTIPLE_USE",
card=Card.Query(
currency="PHP",
card_information=CardInformation.Query(
card_number="4000000000000002",
expiry_month="12",
expiry_year="2040"
),
channel_properties=CardChannelProperties.Query(
failure_return_url="https://redirect.me/badstuff",
success_return_url="https://redirect.me/goodstuff"
)
)
)

self.assert_returned_object_has_same_key_as_sample_response(
payment_method, payment_method_response()
)

def test_create_card_return_correct_keys(self, PaymentMethod):
payment_method = PaymentMethod.create(
type="CARD",
reusability="MULTIPLE_USE",
card=Card.Query(
currency="PHP",
card_information=CardInformation.Query(
card_number="4000000000000002",
expiry_month="12",
expiry_year="2040"
),
channel_properties=CardChannelProperties.Query(
failure_return_url="https://redirect.me/badstuff",
success_return_url="https://redirect.me/goodstuff"
)
)
)

self.assert_returned_object_has_same_key_as_sample_response(
payment_method, payment_method_response()
)

def test_create_over_the_counter_return_correct_keys(self, PaymentMethod):
payment_method = PaymentMethod.create(
type="OVER_THE_COUNTER",
reusability="ONE_TIME_USE",
over_the_counter=OverTheCounter.Query(
amount=50,
currency="PHP",
channel_code="7ELEVEN",
channel_properties=OTCChannelProperties.Query(
customer_name="Test Customer"
)
)
)

self.assert_returned_object_has_same_key_as_sample_response(
payment_method, payment_method_response()
)

def test_create_qr_code_return_correct_keys(self, PaymentMethod):
payment_method = PaymentMethod.create(
type="QR_CODE",
reusability="ONE_TIME_USE",
qr_code=QRCode.Query(
amount=50,
currency="PHP",
channel_code="RCBC",
)
)

self.assert_returned_object_has_same_key_as_sample_response(
payment_method, payment_method_response()
)

def test_create_virtual_account_return_correct_keys(self, PaymentMethod):
payment_method = PaymentMethod.create(
type="VIRTUAL_ACCOUNT",
reusability="MULTIPLE_USE",
virtual_account=VirtualAccount.Query(
channel_code="BCA",
channel_properties=VAChannelProperties.Query(
customer_name="Test Customer"
)
)
)

self.assert_returned_object_has_same_key_as_sample_response(
payment_method, payment_method_response()
)

def test_update_return_correct_keys(self, PaymentMethod):
payment_method = PaymentMethod.update(
payment_method_id="pm-1c229762-c21a-433d-8da5-f02240387e34",
status="INACTIVE"
)

self.assert_returned_object_has_same_key_as_sample_response(
payment_method, payment_method_response()
)

def test_expire_return_correct_keys(self, PaymentMethod):
payment_method = PaymentMethod.create(
type="EWALLET",
reusability="ONE_TIME_USE",
ewallet=EWallet.Query(
channel_code="PAYMAYA",
channel_properties=EWalletChannelProperties.Query(
cancel_return_url="https://redirect.me/nostuff",
failure_return_url="https://redirect.me/badstuff",
success_return_url="https://redirect.me/goodstuff"
)
)
)

expire_result = PaymentMethod.expire(
payment_method_id=payment_method.id
)

self.assert_returned_object_has_same_key_as_sample_response(
payment_method, payment_method_response()
)

def test_list_return_correct_keys(self, PaymentMethod):
payment_method_list = PaymentMethod.list(limit=5)

for payment_method in payment_method_list.data:
self.assert_returned_object_has_same_key_as_sample_response(
payment_method, payment_method_response()
)
48 changes: 48 additions & 0 deletions tests/integration/test_payment_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest
from tests.sampleresponse.payment_request import payment_request_response
from xendit.models.paymentmethod.ewallet.channel_properties import \
ChannelProperties as EWalletChannelProperties
from xendit.models.paymentmethod.ewallet.ewallet import EWallet
from xendit.models.paymentmethod import PaymentMethod
from .base_integration_test import BaseIntegrationTest


class TestPaymentRequest(BaseIntegrationTest):
@pytest.fixture
def PaymentRequest(self, xendit_instance):
return xendit_instance.PaymentRequest

def test_get_return_correct_keys(self, PaymentRequest):
payment_request = PaymentRequest.get(payment_request_id ="ewc_f02159c3-1e52-48a4-974f-243d906a5da3")
self.assert_returned_object_has_same_key_as_sample_response(
payment_request, payment_request_response()
)

# def test_create_paymereturn_correct_keys(self, xendit_instance):

# payment_request = xendit_instance.PaymentRequest.create(
# amount=1500,
# currency="IDR",
# payment_method=PaymentMethod.Query(
# type="EWALLET",
# reusability="ONE_TIME_USE",
# ewallet=EWallet.Query(
# channel_code="OVO",
# channel_properties=EWalletChannelProperties.Query(
# mobile_number="+628123123123"
# )
# )
# )
# )

# self.assert_returned_object_has_same_key_as_sample_response(
# payment_request, payment_request_response()
# )

def test_list_return_correct_keys(self, PaymentRequest):
payment_request_list = PaymentRequest.list(limit=5)

for payment_request in payment_request_list.data:
self.assert_returned_object_has_same_key_as_sample_response(
payment_request, payment_request_response()
)
Loading

0 comments on commit 758845c

Please sign in to comment.