Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Commit

Permalink
Features/internet bank (#14)
Browse files Browse the repository at this point in the history
* 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
Show file tree
Hide file tree
Showing 12 changed files with 542 additions and 29 deletions.
172 changes: 172 additions & 0 deletions tests/internet_banking_tests.py
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)

12 changes: 6 additions & 6 deletions tests/live_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ def test_preauth_capture(self):
pass


class PermataVA_AcceptanceTests_v0_8(unittest.TestCase):
class PermataVA_AcceptanceTests_v0_9(unittest.TestCase):

VERSION = '0.8'
VERSION = '0.9'

def setUp(self):
if None in [SANDBOX_CLIENT_KEY, SANDBOX_SERVER_KEY]:
Expand Down Expand Up @@ -246,9 +246,9 @@ def test_virtualaccountpermata(self):
self.assertEqual(self.trans_details.order_id, resp.order_id)


class BriEpay_AcceptanceTests_v0_8(unittest.TestCase):
class BriEpay_AcceptanceTests_v0_9(unittest.TestCase):

VERSION = '0.8'
VERSION = '0.9'

def setUp(self):
if None in [SANDBOX_CLIENT_KEY, SANDBOX_SERVER_KEY]:
Expand Down Expand Up @@ -309,9 +309,9 @@ def test_briepay(self):
self.assertEqual(self.trans_details.order_id, resp.order_id)


class MandiriVA_AcceptanceTests_v0_8(unittest.TestCase):
class MandiriVA_AcceptanceTests_v0_9(unittest.TestCase):

VERSION = '0.8'
VERSION = '0.9'

def setUp(self):
if None in [SANDBOX_CLIENT_KEY, SANDBOX_SERVER_KEY]:
Expand Down
74 changes: 73 additions & 1 deletion tests/payment_types_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from faker import Faker

from veritranspay.payment_types import CreditCard, Indomaret, VirtualAccountPermata, VirtualAccountBca, \
VirtualAccountBni, VirtualAccountMandiri, BriEpay
VirtualAccountBni, VirtualAccountMandiri, BriEpay, MandiriClickpay, CimbClicks, BCAKlikPay, KlikBCA

fake = Faker()

Expand Down Expand Up @@ -149,3 +149,75 @@ def test_serialization(self):
}

self.assertDictEqual(expected, bri.serialize())


class BCAKliPayTest(unittest.TestCase):
def test_serialization(self):
bca_klikpay = BCAKlikPay(type_id=1, description="Pembelian Barang")

expected = {
'payment_type': 'bca_klikpay',
'bca_klikpay': {
'type': 1,
'description': 'Pembelian Barang'
}
}

self.assertDictEqual(expected, bca_klikpay.serialize())


class KlikBCATest(unittest.TestCase):

def test_serialization(self):
klik_bca = KlikBCA(user_id="midtrans1012", description="testing transaction")

expected = {
'payment_type': 'bca_klikbca',
'bca_klikbca': {
'description': 'testing transaction',
'user_id': 'midtrans1012'
}
}

self.assertDictEqual(expected, klik_bca.serialize())


class MandiriClickpayTest(unittest.TestCase):

def test_serialization(self):
data_init = {
'card_number': '4111111111111111',
'input1': '1111111111',
'input2': '145000',
'input3': '54321',
'token': '000000'
}

mandiri_clickpay = MandiriClickpay(**data_init)

expected = {
'payment_type': 'mandiri_clickpay',
'mandiri_clickpay': {
'card_number': '4111111111111111',
'input1': '1111111111',
'input2': '145000',
'input3': '54321',
'token': '000000'
}
}

self.assertDictEqual(expected, mandiri_clickpay.serialize())


class CimbClicksTest(unittest.TestCase):
def test_serialization(self):
cimb_clicks = CimbClicks(description='Purchase of a special event item')

expected = {
'payment_type': 'cimb_clicks',
'cimb_clicks': {
'description': 'Purchase of a special event item'
}
}

self.assertDictEqual(expected, cimb_clicks.serialize())
37 changes: 37 additions & 0 deletions tests/response_bca_klikbca_tests.py
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)

31 changes: 31 additions & 0 deletions tests/response_bcaklikpay_tests.py
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)

30 changes: 30 additions & 0 deletions tests/response_cimb_klikpay_tests.py
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)

Loading

0 comments on commit 720e991

Please sign in to comment.