Skip to content

Commit

Permalink
chore: Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
cassiewang committed Nov 2, 2022
1 parent 2abf0aa commit 87832e3
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
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()

0 comments on commit 87832e3

Please sign in to comment.