{ "info": { "author": "Rizda Prasetya", "author_email": "rizda.prasetya@midtrans.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Midtrans Client - Python\n===============\n\n[](https://travis-ci.org/rizdaprasetya/midtrans-python-client)\n[](https://badge.fury.io/py/midtransclient)\n[](https://pepy.tech/project/midtransclient)\n[](https://pepy.tech/project/midtransclient)\n\nMidtrans \u2764\ufe0f Python! \ud83d\udc0d\n\nThis is the Official Python API client/library for Midtrans Payment API. Visit [https://midtrans.com](https://midtrans.com). More information about the product and see documentation at [http://docs.midtrans.com](https://docs.midtrans.com) for more technical details.\n\n## 1. Installation\n\n### 1.a Using Pip\n\n```\npip install midtransclient\n```\n\n### 1.b Manual Installation\n\nIf you are not using Pip, you can clone or [download](https://github.com/midtrans/midtrans-python-client/archive/master.zip) this repository.\nThen import from `midtransclient` folder.\n\nOr run Pip install from the repo folder.\n```\npip install .\n```\n\n## 2. Usage\n\n### 2.1 Choose Product/Method\n\nWe have [2 different products](https://docs.midtrans.com/en/welcome/index.html) of payment that you can use:\n- [Snap](#22A-snap) - Customizable payment popup will appear on **your web/app** (no redirection). [doc ref](https://snap-docs.midtrans.com/)\n- [Snap Redirect](#22B-snap-redirect) - Customer need to be redirected to payment url **hosted by midtrans**. [doc ref](https://snap-docs.midtrans.com/)\n- [Core API (VT-Direct)](#22C-core-api-vt-direct) - Basic backend implementation, you can customize the frontend embedded on **your web/app** as you like (no redirection). [doc ref](https://api-docs.midtrans.com/)\n\nChoose one that you think best for your unique needs.\n\n### 2.2 Client Initialization and Configuration\n\nGet your client key and server key from [Midtrans Dashboard](https://dashboard.midtrans.com)\n\nCreate API client object\n\n```python\n# Create Core API instance\ncore_api = midtransclient.CoreApi(\n is_production=False,\n server_key='YOUR_SERVER_KEY',\n client_key='YOUR_CLIENT_KEY'\n)\n```\n\n\n```python\n# Create Snap API instance\nsnap = midtransclient.Snap(\n is_production=False,\n server_key='YOUR_SERVER_KEY',\n client_key='YOUR_CLIENT_KEY'\n)\n```\n\nYou can also re-set config using `Snap.api_config.set( ... )`\nexample:\n\n```python\n\n# initialize object, empty config\nsnap = midtransclient.Snap()\n\n# re-set full config\nsnap.api_config.set(\n is_production=False,\n server_key='YOUR_SERVER_KEY',\n client_key='YOUR_CLIENT_KEY'\n)\n\n# re-set server_key only\nsnap.api_config.set(server_key='YOUR_SERVER_KEY')\n\n# re-set is_production only\nsnap.api_config.set(is_production=True)\n```\n\nYou can also set config directly from attribute\n```python\n# initialize object, empty config\nsnap = midtransclient.Snap()\n\n# set config\nsnap.api_config.is_production=False\nsnap.api_config.server_key='YOUR_SERVER_KEY'\nsnap.api_config.client='YOUR_CLIENT_KEY'\n```\n\n\n### 2.2.A Snap\nYou can see Snap example [here](examples/snap).\n\nAvailable methods for `Snap` class\n```python\n# return Snap API /transaction response as Dictionary\ndef create_transactions(parameter):\n\n# return Snap API /transaction token as String\ndef create_transactions_token(parameter):\n\n# return Snap API /transaction redirect_url as String\ndef create_transactions_redirect_url(parameter):\n```\n`parameter` is Dictionary or String of JSON of [SNAP Parameter](https://snap-docs.midtrans.com/#json-objects)\n\n\n#### Get Snap Token\n\n```python\n# Create Snap API instance\nsnap = midtransclient.Snap(\n is_production=False,\n server_key='YOUR_SERVER_KEY',\n client_key='YOUR_CLIENT_KEY'\n)\n# Build API parameter\nparam = {\n \"transaction_details\": {\n \"order_id\": \"test-transaction-123\",\n \"gross_amount\": 200000\n }, \"credit_card\":{\n \"secure\" : True\n }\n}\n\ntransaction = snap.create_transaction(param)\n\ntransaction_token = transaction['token']\n# alternative way to create transaction_token:\n# transaction_token = snap.create_transaction_token(param)\n```\n\n\n#### Initialize Snap JS when customer click pay button\n\nReplace `PUT_TRANSACTION_TOKEN_HERE` with `transaction_token` acquired above\n```html\n\n
\n \n\n\n\n \n \n \n\n```\n\n#### Implement Notification Handler\n[Refer to this section](#23-handle-http-notification)\n\n### 2.2.B Snap Redirect\n\nAlso available as examples [here](examples/snap).\n\n#### Get Redirection URL of a Payment Page\n\n```python\n# Create Snap API instance\nsnap = midtransclient.Snap(\n is_production=False,\n server_key='YOUR_SERVER_KEY',\n client_key='YOUR_CLIENT_KEY'\n)\n# Build API parameter\nparam = {\n \"transaction_details\": {\n \"order_id\": \"test-transaction-123\",\n \"gross_amount\": 200000\n }, \"credit_card\":{\n \"secure\" : True\n }\n}\n\ntransaction = snap.create_transaction(param)\n\ntransaction_redirect_url = transaction['redirect_url']\n# alternative way to create redirect_url:\n# transaction_redirect_url = snap.create_redirect_url(param)\n```\n#### Implement Notification Handler\n[Refer to this section](#23-handle-http-notification)\n\n### 2.2.C Core API (VT-Direct)\n\nYou can see some Core API examples [here](examples/core_api).\n\nAvailable methods for `CoreApi` class\n```python\ndef charge(self,parameters=dict()):\n \"\"\"\n Trigger `/charge` API call to Core API\n :param parameters: dictionary of Core API JSON body as parameter, will be converted to JSON\n (more params detail refer to: https://api-docs.midtrans.com)\n\n :return: Dictionary from JSON decoded response\n \"\"\"\n\ndef capture(self,parameters=dict()):\n \"\"\"\n Trigger `/capture` API call to Core API\n Capture is only used for pre-authorize transaction only\n :param parameters: dictionary of Core API JSON body as parameter, will be converted to JSON\n (more params detail refer to: https://api-docs.midtrans.com)\n\n :return: Dictionary from JSON decoded response\n \"\"\"\n\ndef card_register(self,parameters=dict()):\n \"\"\"\n Trigger `/card/register` API call to Core API\n :param parameters: dictionary of Core API JSON body as parameter, will be converted to JSON\n (more params detail refer to: https://api-docs.midtrans.com)\n\n :return: Dictionary from JSON decoded response\n \"\"\"\n\ndef card_token(self,parameters=dict()):\n \"\"\"\n Trigger `/token` API call to Core API\n :param parameters: dictionary of Core API JSON body as parameter, will be converted to JSON\n (more params detail refer to: https://api-docs.midtrans.com)\n\n :return: Dictionary from JSON decoded response\n \"\"\"\n\ndef card_point_inquiry(self,token_id):\n \"\"\"\n Trigger `/point_inquiry/JSON result will appear here after payment: