-
Notifications
You must be signed in to change notification settings - Fork 27
/
core_api_simple_example.py
43 lines (39 loc) · 1.44 KB
/
core_api_simple_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import midtransclient
# This is just for very basic implementation reference, in production, you should validate the incoming requests and implement your backend more securely.
# Initialize core api client object
# You can find it in Merchant Portal -> Settings -> Access keys
core = midtransclient.CoreApi(
is_production=False,
server_key='YOUR_SERVER_KEY',
client_key='YOUR_CLIENT_KEY'
)
# prepare CORE API parameter ( refer to: https://docs.midtrans.com/en/core-api/bank-transfer?id=sample-request-and-request-body ) charge bank_transfer parameter example
param = {
"payment_type": "bank_transfer",
"transaction_details": {
"gross_amount": 24145,
"order_id": "test-transaction-321",
},
"bank_transfer":{
"bank": "bni"
}
}
# charge transaction
charge_response = core.charge(param)
print('charge_response:')
print(charge_response)
# charge_response is dictionary representation of API JSON response
# sample:
# {
# 'currency': 'IDR',
# 'fraud_status': 'accept',
# 'gross_amount': '24145.00',
# 'order_id': 'test-transaction-321',
# 'payment_type': 'bank_transfer',
# 'status_code': '201',
# 'status_message': 'Success, Bank Transfer transaction is created',
# 'transaction_id': '6ee793df-9b1d-4343-8eda-cc9663b4222f',
# 'transaction_status': 'pending',
# 'transaction_time': '2018-10-24 15:34:33',
# 'va_numbers': [{'bank': 'bca', 'va_number': '490526303019299'}]
# }