Skip to content

Commit

Permalink
charge_credit_card()
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalebu committed Nov 13, 2021
1 parent 34ecb62 commit d81c0df
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 62 deletions.
35 changes: 24 additions & 11 deletions DirectPayOnline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
MobilePaymentsOptionsModel,
ChargeTokenAuthModel,
BankTransferOptionsModel,
ChargeCreditCardModel,
)
from .xml_templates import (
create_token_xml,
Expand All @@ -36,6 +37,7 @@
create_mobile_payment_options_xml,
create_charge_token_auth_xml,
create_bank_transfer_options_xml,
create_charge_credit_card_xml,
)


Expand Down Expand Up @@ -172,7 +174,7 @@ def create_token(self, user_query: dict) -> dict:
final_query = self.get_final_query(user_query)

# validate query
query = CreateTokenModel.validate(final_query).dict()
query = CreateTokenModel(**final_query).dict()

# construct xml request body and send it to DPO API
xml_data = create_token_xml(query)
Expand All @@ -192,7 +194,7 @@ def email_to_token(self, query: dict) -> str:
final_query = self.get_final_query(query)

# validate query
query = EmailtoTokenModel.validate(final_query).dict()
query = EmailtoTokenModel(**final_query).dict()

# construct xml request body and send it to DPO API
xml_data = create_email_to_token_xml(query)
Expand All @@ -210,7 +212,7 @@ def create_mvisa_qrcode(self, user_query: dict) -> str:
final_query = self.get_final_query(user_query)

# validate query
query = CreateMvisaQrcodeModel.validate(final_query).dict()
query = CreateMvisaQrcodeModel(**final_query).dict()

# construct xml request body and send it to DPO API
xml_data = create_mvisa_qrcode_xml(query)
Expand All @@ -221,7 +223,7 @@ def refund_token(self, query: dict) -> str:
final_query = self.get_final_query(query)

# validate query
query = RefundTokenModel.validate(final_query).dict()
query = RefundTokenModel(**final_query).dict()

# construct xml request body and send it to DPO API
xml_data = create_refund_token_xml(query)
Expand All @@ -232,7 +234,7 @@ def update_token(self, query: dict) -> str:
final_query = self.get_final_query(query)

# validate query
query = UpdateTokenModel.validate(final_query).dict()
query = UpdateTokenModel(**final_query).dict()

# construct xml request body and send it to DPO API
xml_data = create_update_token_xml(query)
Expand All @@ -243,7 +245,7 @@ def verify_token(self, user_query: dict):
final_query = self.get_final_query(user_query)

# validate query
query = VerifyTokenModel.validate(final_query).dict()
query = VerifyTokenModel(**final_query).dict()

# construct xml request body and send it to DPO API
xml_data = create_verify_token_xml(query)
Expand All @@ -254,7 +256,7 @@ def verify_xpay(self, user_query: dict):
final_query = self.get_final_query(user_query)

# validate query
query = VerifyXpayModel.validate(final_query).dict()
query = VerifyXpayModel(**final_query).dict()

# construct xml request body and send it to DPO API
xml_data = create_verify_xpay_xml(query)
Expand All @@ -265,7 +267,7 @@ def cancel_token(self, user_query: dict):
final_query = self.get_final_query(user_query)

# validate query
query = CancelTokenModel.validate(final_query).dict()
query = CancelTokenModel(**final_query).dict()

# construct xml request body and send it to DPO API
xml_data = create_cancel_token_xml(query)
Expand All @@ -281,7 +283,7 @@ def mobile_payment_options(self, user_query: dict):
final_query = self.get_final_query(user_query)

# validate the query
query = MobilePaymentsOptionsModel.validate(final_query).dict()
query = MobilePaymentsOptionsModel(**final_query).dict()
print(query)
# construct xml and send request to DPO API
xml_data = create_mobile_payment_options_xml(query)
Expand All @@ -292,7 +294,7 @@ def charge_token_auth(self, user_query: dict):
final_query = self.get_final_query(user_query)

# validate the query
query = ChargeTokenAuthModel.validate(final_query)
query = ChargeTokenAuthModel(**final_query)

# construct xml and send it to DPO API
xml = create_charge_token_auth_xml(query)
Expand All @@ -303,8 +305,19 @@ def bank_transfer_options(self, user_query: dict):
final_query = self.get_final_query(user_query)

# validate the query
query = BankTransferOptionsModel.validate(final_query).dict()
query = BankTransferOptionsModel(**final_query).dict()

# construct xml and send it to DPO API
xml = create_bank_transfer_options_xml(query)
return self.post(xml)

def charge_credit_card(self, user_query: dict):
# get the final query
final_query = self.get_final_query(user_query)

# validate the query
query = ChargeCreditCardModel(**final_query).dict()

# construct xml and send it to DPO
xml = create_charge_credit_card_xml(query)
return self.post(xml)
60 changes: 15 additions & 45 deletions DirectPayOnline/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,37 +78,23 @@ class CreateTokenModel(BaseModel):
traveller_phone: str = None
traveller_phone_prefix: int = None

@staticmethod
def validate(body: dict):
return CreateTokenModel(**body)


class UpdateTokenModel(CreateTokenModel):
request_type = "updateToken"
transtoken: str
user_token: str = None

@staticmethod
def validate(body: dict):
return UpdateTokenModel(**body)


class EmailtoTokenModel(BaseModel):
company_token: str
request_type: str = "emailToToken"
company_token: str
transtoken: str

@staticmethod
def validate(body: dict):
return EmailtoTokenModel(**body)


class CreateMvisaQrcodeModel(EmailtoTokenModel):
class CreateMvisaQrcodeModel(BaseModel):
request_type: str = "createMvisaQRcode"

@staticmethod
def validate(body: dict):
return CreateMvisaQrcodeModel(**body)
company_token: str
transtoken: str


class RefundTokenModel(BaseModel):
Expand All @@ -118,66 +104,50 @@ class RefundTokenModel(BaseModel):
amount: float
description: str = None

@staticmethod
def validate(body: dict):
return RefundTokenModel(**body)


class VerifyTokenModel(BaseModel):
company_token: str
request_type: str = "verifyToken"
transtoken: str

@staticmethod
def validate(body: dict):
return VerifyTokenModel(**body)


class VerifyXpayModel(BaseModel):
company_token: str
request_type: str = "verifyXpay"
xpay_id: str

@staticmethod
def validate(body: dict):
return VerifyXpayModel(**body)


class CancelTokenModel(BaseModel):
request_type: str = "cancelToken"
company_token: str
transtoken: str

@staticmethod
def validate(body: dict):
return CancelTokenModel(**body)


class MobilePaymentsOptionsModel(BaseModel):
request_type: str = "GetMobilePaymentOptions"
company_token: str
transtoken: str

@staticmethod
def validate(body: dict):
return MobilePaymentsOptionsModel(**body)


class ChargeTokenAuthModel(BaseModel):
request_type: str = "chargeTokenAuth"
company_token: str
transtoken: str

@staticmethod
def validate(body: dict):
return ChargeTokenAuthModel(**body)


class BankTransferOptionsModel(BaseModel):
request_type: str = "GetBankTransferOptions"
company_token: str
transtoken: str

@staticmethod
def validate(body: dict):
return BankTransferOptionsModel(**body)

class ChargeCreditCardModel(BaseModel):
request_type: str = "chargeTokenCreditCard"
company_token: str
transtoken: str
card_number: int
card_expiry: str
card_cvv: str
card_holder_name: str
charge_type: str = None
three_d: str = None
23 changes: 22 additions & 1 deletion DirectPayOnline/xml_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@
"""
)

# ============== XML template (charge_credit card )==============
credit_card_xml_string = (
header_xml
+ """
<TransactionToken>{transtoken}</TransactionToken>
<CreditCardNumber>{card_number}</CreditCardNumber>
<CreditCardExpiry>{card_expiry}</CreditCardExpiry>
<CreditCardCVV>{card_cvv}</CreditCardCVV>
<CardHolderName>{card_holder_name}</CardHolderName>
</API3G>
"""
)


def remove_none_tags(xml_string: str) -> str:
"""
Expand Down Expand Up @@ -208,7 +221,15 @@ def create_charge_token_auth_xml(data: dict) -> str:

def create_bank_transfer_options_xml(data: dict) -> str:
"""
Function to creating XML for Bank transfers options
Function for creating XML for Bank transfers options
"""
data = verify_token_xml_tring.format(**data)
return remove_none_tags(data)


def create_charge_credit_card_xml(data: dict) -> str:
"""
Function for creating XML to charge credit card
"""
data = credit_card_xml_string.format(**data)
return remove_none_tags(data)
22 changes: 17 additions & 5 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,24 @@
# print("Damn")


# =============== mobile payment options ===============
response = gateway.mobile_payment_options(query)
print(response)
# # =============== mobile payment options ===============
# response = gateway.mobile_payment_options(query)
# print(response)

# # =============== bank transfer options ====================
# response = gateway.bank_transfer_options(query)
# print(response)

# =============== bank transfer options ====================
response = gateway.bank_transfer_options(query)
# ============== charge credit card =========================
query.update(
{
"card_number": 122323232323,
"card_expiry": "0242",
"card_cvv": "323",
"card_holder_name": "Jordan Gwalugano",
}
)
response = gateway.charge_credit_card(query)
print(response)

print("==========================DAMN=========================")

0 comments on commit d81c0df

Please sign in to comment.