This repository has been archived by the owner on Jul 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Internet Banking features. * Change response for internet banking, update version to 0.9 and add payment_types test for internet banking.
- Loading branch information
Yanwar Solahudin
authored and
Derek J. Curtis
committed
Jul 6, 2017
1 parent
4d3e49b
commit 720e991
Showing
12 changed files
with
542 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
import random | ||
import unittest | ||
import os | ||
|
||
import requests | ||
from requests import codes | ||
|
||
from faker import Faker | ||
fake = Faker() | ||
|
||
import veritranspay | ||
from veritranspay import request, veritrans, payment_types, response | ||
from veritranspay.response import status | ||
|
||
from . import fixtures | ||
|
||
|
||
SANDBOX_CLIENT_KEY = os.environ.get('SANDBOX_CLIENT_KEY', None) | ||
SANDBOX_SERVER_KEY = os.environ.get('SANDBOX_SERVER_KEY', None) | ||
RUN_ALL_ACCEPTANCE_TESTS = os.environ.get('RUN_ALL_ACCEPTANCE_TESTS', False) | ||
|
||
|
||
class InternetBankingTests_Base(object): | ||
|
||
def setUp(self): | ||
if None in [SANDBOX_CLIENT_KEY, SANDBOX_SERVER_KEY]: | ||
self.skipTest("Live credentials not provided -- skipping tests") | ||
if not RUN_ALL_ACCEPTANCE_TESTS and \ | ||
self.VERSION != veritranspay.__version__: | ||
self.skipTest("Skipping this version of tests") | ||
|
||
expected = fixtures.CC_REQUEST | ||
self.expected = expected | ||
|
||
self.trans_details = request.TransactionDetails( | ||
order_id="".join([fake.random_letter() for _ in range(10)]), | ||
gross_amount=expected['transaction_details']['gross_amount']) | ||
|
||
self.cust_details = request.CustomerDetails( | ||
first_name=expected['customer_details']['first_name'], | ||
last_name=expected['customer_details']['last_name'], | ||
email=expected['customer_details']['email'], | ||
phone=expected['customer_details']['phone'], | ||
billing_address=request.Address( | ||
**expected['customer_details']['billing_address']), | ||
shipping_address=request.Address( | ||
**expected['customer_details']['shipping_address']) | ||
) | ||
|
||
self.item_details = \ | ||
[request.ItemDetails(item_id=item['id'], | ||
price=item['price'], | ||
quantity=item['quantity'], | ||
name=item['name']) | ||
for item | ||
in expected['item_details']] | ||
|
||
|
||
class MandiriClickpayTests_v0_9(InternetBankingTests_Base, unittest.TestCase): | ||
|
||
VERSION = '0.9' | ||
|
||
def test_mandiri_click_pay_charge(self): | ||
# 1: Create a sandbox gateway | ||
gateway = veritrans.VTDirect( | ||
server_key=SANDBOX_SERVER_KEY, | ||
sandbox_mode=True) | ||
|
||
# 2: Set payment type Internet Banking from Mandiri Click pay | ||
mandiri_clickpay = payment_types.MandiriClickpay( | ||
card_number="4111111111111111", | ||
input1="1111111111", | ||
input2="145000", | ||
input3="54321", | ||
token="000000") | ||
|
||
# 3: Create a charge request | ||
charge_req = request.ChargeRequest( | ||
charge_type=mandiri_clickpay, | ||
transaction_details=self.trans_details, | ||
customer_details=self.cust_details, | ||
item_details=self.item_details) | ||
|
||
# 4: Submit our request | ||
resp = gateway.submit_charge_request(charge_req) | ||
|
||
self.assertIsInstance(resp, response.MandiriChargeResponse) | ||
self.assertEqual(status.SUCCESS, resp.status_code) | ||
|
||
|
||
class CimbClicksTests_v0_9(InternetBankingTests_Base, unittest.TestCase): | ||
|
||
VERSION = '0.9' | ||
|
||
def test_cimb_clicks_charge(self): | ||
# 1: Create a sandbox gateway | ||
gateway = veritrans.VTDirect( | ||
server_key=SANDBOX_SERVER_KEY, | ||
sandbox_mode=True) | ||
|
||
# 2: Set payment type to Cimb Clicks internet banking. | ||
cimb_clicks = payment_types.CimbClicks( | ||
description="Purchase of a special event item") | ||
|
||
# 3: Create a charge request | ||
charge_req = request.ChargeRequest( | ||
charge_type=cimb_clicks, | ||
transaction_details=self.trans_details, | ||
customer_details=self.cust_details, | ||
item_details=self.item_details) | ||
|
||
# 4: Submit our request | ||
resp = gateway.submit_charge_request(charge_req) | ||
|
||
self.assertIsInstance(resp, response.CimbsChargeResponse) | ||
self.assertEqual(status.CHALLENGE, resp.status_code) | ||
|
||
|
||
class BCAKlikPayTests_v0_9(InternetBankingTests_Base, unittest.TestCase): | ||
|
||
VERSION = '0.9' | ||
|
||
def test_bcaklikpay_charger(self): | ||
# 1: Create a sandbox gateway | ||
gateway = veritrans.VTDirect( | ||
server_key=SANDBOX_SERVER_KEY, | ||
sandbox_mode=True) | ||
|
||
# 2: Set Internet banking BCA Klik pay | ||
bca_klikpay = payment_types.BCAKlikPay(type_id=1, description="Pembelian barang") | ||
|
||
# 3: Create a charge request | ||
charge_req = request.ChargeRequest( | ||
charge_type=bca_klikpay, | ||
transaction_details=self.trans_details, | ||
customer_details=self.cust_details, | ||
item_details=self.item_details) | ||
|
||
# 4: Submit our request | ||
resp = gateway.submit_charge_request(charge_req) | ||
|
||
self.assertIsInstance(resp, response.BCAKlikPayChargeResponse) | ||
self.assertEqual(status.CHALLENGE, resp.status_code) | ||
|
||
|
||
class KlikBCATests_v0_9(InternetBankingTests_Base, unittest.TestCase): | ||
|
||
VERSION = '0.9' | ||
|
||
def test_klikbca_charger(self): | ||
# 1: Create a sandbox gateway | ||
gateway = veritrans.VTDirect( | ||
server_key=SANDBOX_SERVER_KEY, | ||
sandbox_mode=True) | ||
|
||
# 2: Set Internet banking Klik BCA | ||
klik_bca = payment_types.KlikBCA(user_id="midtrans1014", # error | ||
description="Testing transaction") | ||
|
||
# 3: Create a charge request | ||
charge_req = request.ChargeRequest( | ||
charge_type=klik_bca, | ||
transaction_details=self.trans_details, | ||
customer_details=self.cust_details, | ||
item_details=self.item_details) | ||
|
||
# 4: Submit our request | ||
resp = gateway.submit_charge_request(charge_req) | ||
|
||
self.assertIsInstance(resp, response.KlikBCAChargeResponse) | ||
self.assertEqual(status.CHALLENGE, resp.status_code) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from unittest import TestCase | ||
|
||
from veritranspay.response.response import EpayBriChargeResponse | ||
|
||
|
||
class EpayBriChargeResponseTests_v0_9(TestCase): | ||
""" | ||
https://api-docs.midtrans.com/#epay-bri | ||
""" | ||
|
||
def setUp(self): | ||
# example response data from | ||
# https://api-docs.midtrans.com/#permata-virtual-account | ||
self.response_json = { | ||
"status_code": "201", | ||
"status_message": "OK, BCA KlikPay transaction is successful", | ||
"transaction_id": "ada84cd9-2233-4c67-877a-01884eece45e", | ||
"order_id": "orderid-01", | ||
"redirect_url": "https://api.sandbox.veritrans.co.id/v3/bca/klikpay/redirect/ada84cd9-2233-4c67-877a-01884eece45e", | ||
"gross_amount": "11000.00", | ||
"payment_type": "bca_klikpay", | ||
"transaction_time": "2016-06-19 15:42:36", | ||
"transaction_status": "pending", | ||
"fraud_status": "accept" | ||
} | ||
|
||
self.parsed_response = EpayBriChargeResponse(**self.response_json) | ||
|
||
def test_status_code(self): | ||
self.assertEqual(201, self.parsed_response.status_code) | ||
|
||
def test_payment_type(self): | ||
self.assertEqual('bca_klikpay', self.parsed_response.payment_type) | ||
|
||
def test_redirect_url(self): | ||
self.assertEqual('https://api.sandbox.veritrans.co.id/v3/bca/klikpay/redirect/ada84cd9-2233-4c67-877a-01884eece45e', self.parsed_response.redirect_url) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from unittest import TestCase | ||
|
||
from veritranspay.response import BCAKlikPayChargeResponse | ||
|
||
|
||
class BCAKlikPayChargeResponseTests_v0_9(TestCase): | ||
|
||
def setUp(self): | ||
# example response data from | ||
# http://api-docs.midtrans.com/#bca-klikpay | ||
self.response_json = { | ||
"status_code": "201", | ||
"status_message": "OK, BCA KlikPay transaction is successful", | ||
"transaction_id": "ada84cd9-2233-4c67-877a-01884eece45e", | ||
"order_id": "orderid-01", | ||
"redirect_url": "https://api.sandbox.veritrans.co.id/v3/bca/klikpay/redirect/ada84cd9-2233-4c67-877a-01884eece45e", | ||
"gross_amount": "11000.00", | ||
"payment_type": "bca_klikpay", | ||
"transaction_time": "2016-06-19 15:42:36", | ||
"transaction_status": "pending", | ||
"fraud_status": "accept" | ||
} | ||
|
||
self.parsed_response = BCAKlikPayChargeResponse(**self.response_json) | ||
|
||
def test_status_code(self): | ||
self.assertEqual(201, self.parsed_response.status_code) | ||
|
||
def test_payment_type(self): | ||
self.assertEqual('bca_klikpay', self.parsed_response.payment_type) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from unittest import TestCase | ||
|
||
from veritranspay.response import CimbsChargeResponse | ||
|
||
|
||
class CimbsChargeResponseTests_v0_9(TestCase): | ||
|
||
def setUp(self): | ||
# example response data from | ||
# http://api-docs.midtrans.com/#cimb-clicks | ||
self.response_json = { | ||
"status_code": "201", | ||
"status_message": "Success, CIMB Clicks transaction is successful", | ||
"redirect_url": "https://api.midtrans.com/cimb-clicks/request?id=226f042f-020e-4829-8bd7-2de64b8673ce", | ||
"transaction_id": "226f042f-020e-4829-8bd7-2de64b8673ce", | ||
"order_id": "1000156414164125", | ||
"gross_amount": "392127.00", | ||
"payment_type": "cimb_clicks", | ||
"transaction_time": "2016-06-19 16:41:25", | ||
"transaction_status": "pending" | ||
} | ||
|
||
self.parsed_response = CimbsChargeResponse(**self.response_json) | ||
|
||
def test_status_code(self): | ||
self.assertEqual(201, self.parsed_response.status_code) | ||
|
||
def test_payment_type(self): | ||
self.assertEqual('cimb_clicks', self.parsed_response.payment_type) | ||
|
Oops, something went wrong.