Untitled
unknown
plain_text
4 years ago
4.3 kB
8
Indexable
from django.db import transaction
from django.test import TestCase
import pytest
from .handlers import AmazonPayResponseHandler
from payment.models import PaymentAttempt, PaymentTransaction
# Create your tests here.
GATEWAY_RESPONSE = {
"transaction_code": "14000",
"transaction_status": "14",
"response_code": "12000",
"signature": "072522e4f73cd367977f82ef006b1c635fb5aed69bfcb4fe0e33e8bc2e8dfd3d",
"merchant_identifier": "3e23104d",
"access_code": "iKegmYTRhKpBtrW4DBmL",
"transaction_message": "Success",
"language": "en",
"fort_id": "169996200002021039",
"refunded_amount": "0",
"response_message": "Success",
"merchant_reference": "betabulk45ED3",
"query_command": "CHECK_STATUS",
"captured_amount": "1000",
"authorized_amount": "1000",
"status": "12"
}
@pytest.fixture
def gateway_response():
return GATEWAY_RESPONSE
# payment_transaction = {
# "amount": "100",
# "booking_reference": "beta1201",
# "currency_code": "KWD",
# "customer_email": "dipak.dade@mailinator.com",
# "customer_phone": "+96597979797",
# "gateway_code": "knet",
# "generate_qr_code": False,
# "is_amount_editable": True,
# "language": "en",
# "order_no": "beta1201",
# "remarks": "beta1201",
# "sms_notification": False,
# "test": "beta1201",
# "unit_config": None
# }
import datetime
payment_trans = {
"id": 9089,
"state":"attempted",
"type":"payment_request",
"gateway_code":"",
"pg_codes":[
"amazon-pay"
],
"service_code":"",
"is_sandbox":False,
"is_deleted":False,
"amount":"10.00",
"due_amount":None,
"is_amount_editable":False,
"language":"en",
"currency_code":"AED",
"order_no":"dipak_65456",
"session_id":"",
"bulk":None,
"transaction_log_id":None,
"sms_payment_details":False,
"email_payment_details":True,
"sms_notification":False,
"email_notification":True,
"push_notification":False,
"customer_email":"dipak.dade@kuwaitnet.com",
"customer_phone":"+96597979797",
"vendor_name":"",
"due_date":datetime.date(2021,
8,
2),
"notification_set":None,
"email_recipients":"",
"product_type":"",
"attachment_short_url":"",
"receipt_short_url":"",
"capture_delivery_location":False,
"capture_delivery_address":False,
"seen_at":None,
"initiator":None,
"short_url":"https://pay.kn/2mzxd",
"unit_config":None,
"synced":False,
}
payment_attempt = {
"state":"error",
"transaction":9089,
"reference_number":"betabulkTTFXQ",
"gateway_response":{
"response_code":"12036",
"response_message":"Order not found",
"signature":"1331c485b553247e69319aa49262e54940e535771cd1ad878eb26f80ce0f270a",
"merchant_reference":"betabulkTTFXQ",
"merchant_identifier":"3e23104d",
"query_command":"CHECK_STATUS",
"access_code":"iKegmYTRhKpBtrW4DBmL",
"language":"en",
"status":"12"
},
"settings":None,
"fee":"0.00",
"amount":"10.00",
"total":"10.00",
"data":{
"callback_job_id":"88744eea-056a-440d-a2f6-1e961530c3e3",
"callback_payload":{
"response_code":"12036",
"response_message":"Order not found",
"signature":"1331c485b553247e69319aa49262e54940e535771cd1ad878eb26f80ce0f270a",
"merchant_reference":"betabulkTTFXQ",
"merchant_identifier":"3e23104d",
"query_command":"CHECK_STATUS",
"access_code":"iKegmYTRhKpBtrW4DBmL",
"language":"en",
"status":"12"
}
}
}
@pytest.fixture
def create_payment_transaction():
return PaymentTransaction.objects.create(**payment_trans)
@pytest.fixture
def create_payment_attempt(create_payment_transaction):
return PaymentAttempt.objects.create(**payment_attempt)
# @pytest.fixture
# def payment_attempt(new_payment_transaction):
# return PaymentAttempt.objects.create(transaction=new_payment_transaction)
@pytest.fixture
def handler():
return AmazonPayResponseHandler()
@pytest.mark.django_db
def test_handle_gateway_response(gateway_response, create_payment_attempt, handler):
handler.handle_gateway_response(create_payment_attempt, gateway_response, from_callback=False)
assert True == payment_attempt.is_paid()
Editor is loading...