Skip to content

Commit

Permalink
Merge pull request #20 from mashanz/master
Browse files Browse the repository at this point in the history
[UPD] Add package version var, Deprecate support for python 2 for better python 3 compatibility, fix outdated test
  • Loading branch information
rizdaprasetya authored Oct 25, 2021
2 parents 4d3536a + 51d2d71 commit 3c482b8
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 36 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: python
python:
# - "2.6" # deprecated version of python
- "2.7"
- "3.5"
- "3.6"
- "3.7"
Expand Down
11 changes: 8 additions & 3 deletions Maintaining.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@

- If from scratch, using `pipenv`
- Install pipenv `pip install pipenv` or `pip3 install pipenv`
- If fail, you may need to prefix the command with `sudo `
- CD to project directory
- Install using pipenv `pipenv install`
- If fail, you may need to specify which python bin file by `pipenv install --python /usr/bin/python3`. (Run `which python` or `which python3` to know the file path)
- Activate and enter python env for current folder `pipenv shell`, now you are inside python env
- Install project as local package `pip install -e .`
- Make your code changes
- Increase `version` value on `./setup.py` file
- Increase `version` value on:
- `./setup.py` file
- `./midtransclient/__init__.py` file
- To install the package locally with a symlink `pip install -e .`
- To run test, run `pytest`
- To run specific test, e.g: `pytest -k "test_core_api_charge_fail_401"`
- If fail, you may need to install pytest first `pip install pytest`
- To update https://pypi.org repo, run these on terminal:
```bash
# install setuptools & wheel
Expand All @@ -22,11 +27,11 @@ python -m pip install --upgrade setuptools wheel
python setup.py sdist bdist_wheel

# Update / install Twine
python -m pip install --upgrade twine;
python -m pip install --upgrade twine

# upload to pypi / pip repository
# you will be asked for username and password for https://pypi.org account
twine upload dist/*;
twine upload dist/*

# To upload to test pypi use this instead
# twine upload --repository-url https://test.pypi.org/legacy/ dist/*;
Expand Down
3 changes: 2 additions & 1 deletion examples/flask_app/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
from flask import Flask, render_template, request, jsonify
from midtransclient import Snap, CoreApi

# Set Your server key
# @TODO: Change/fill the following API Keys variable with Your own server & client keys
# You can find it in Merchant Portal -> Settings -> Access keys
SERVER_KEY = 'SB-Mid-server-GwUP_WGbJPXsDzsNEBRs8IYA'
CLIENT_KEY = 'SB-Mid-client-61XuGAwQ8Bj8LxSS'
# Note: by default it uses hardcoded sandbox demo API keys for demonstration purpose

app = Flask(__name__)

Expand Down
4 changes: 3 additions & 1 deletion midtransclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
from .core_api import CoreApi

from .error_midtrans import MidtransAPIError
from .error_midtrans import JSONDecodeError
from .error_midtrans import JSONDecodeError

__version__ = '1.3.0'
13 changes: 0 additions & 13 deletions midtransclient/helpers.py

This file was deleted.

5 changes: 2 additions & 3 deletions midtransclient/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
from .error_midtrans import MidtransAPIError
from .error_midtrans import JSONDecodeError
from .helpers import merge_two_dicts_shallow, _PYTHON_VERSION

class HttpClient(object):
"""
Expand All @@ -29,7 +28,7 @@ def request(self, method, server_key, request_url, parameters=dict(),
"""

# allow string of JSON to be used as parameters
is_parameters_string = isinstance(parameters, str if _PYTHON_VERSION >= (3, 0) else basestring)
is_parameters_string = isinstance(parameters, str)
if is_parameters_string:
try:
parameters = json.loads(parameters)
Expand All @@ -46,7 +45,7 @@ def request(self, method, server_key, request_url, parameters=dict(),

# only merge if custom headers exist
if custom_headers:
headers = merge_two_dicts_shallow(default_headers, custom_headers)
headers = {**default_headers, **headers}

response_object = self.http_client.request(
method,
Expand Down
2 changes: 1 addition & 1 deletion midtransclient/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def refundDirect(self, transaction_id,parameters=dict()):
return response_dict

def notification(self, notification=dict()):
is_notification_string = isinstance(notification, str if sys.version_info[0] >= 3 else basestring)
is_notification_string = isinstance(notification, str)
if is_notification_string:
try:
notification = json.loads(notification)
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setuptools.setup(
name="midtransclient",
version="1.2.0",
version="1.3.0",
author="Rizda Prasetya",
author_email="[email protected]",
license='MIT',
Expand All @@ -23,17 +23,17 @@
packages=setuptools.find_packages(),
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Topic :: Software Development :: Libraries :: Python Modules'
],
python_requires='>=2.7',
python_requires='>=3.5',
install_requires=pkg_req,
tests_requires=test_req
)
3 changes: 3 additions & 0 deletions tests/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Note: keys are intentionally hardcoded, to make test consistent and centralized
USED_SERVER_KEY='SB-Mid-server-GwUP_WGbJPXsDzsNEBRs8IYA'
USED_CLIENT_KEY='SB-Mid-client-61XuGAwQ8Bj8LxSS'
11 changes: 5 additions & 6 deletions tests/test_core_api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import pytest
from .config import USED_SERVER_KEY, USED_CLIENT_KEY
from .helpers import is_str
from .context import midtransclient
import datetime
import json
from pprint import pprint

USED_SERVER_KEY='SB-Mid-server-GwUP_WGbJPXsDzsNEBRs8IYA'
USED_CLIENT_KEY='SB-Mid-client-61XuGAwQ8Bj8LxSS'

REUSED_ORDER_ID = [
"py-midtransclient-test1-"+str(datetime.datetime.now()).replace(" ", "").replace(":", ""),
"py-midtransclient-test2-"+str(datetime.datetime.now()).replace(" ", "").replace(":", ""),
Expand Down Expand Up @@ -56,14 +54,15 @@ def test_core_api_card_register():
SAVED_CC_TOKEN = response['saved_token_id']
assert is_str(response['saved_token_id'])

def test_core_api_card_point_inquiry_fail_402():
def test_core_api_card_point_inquiry_valid_bni_card():
core = generate_core_api_instance()
try:
response = core.card_point_inquiry(CC_TOKEN)
except Exception as e:
err = e
assert 'MidtransAPIError' in err.__class__.__name__
assert '402' in err.message
assert is_str(response['status_message'])
assert 'Success' in response['status_message']
assert is_str(response['point_balance_amount'])


def test_core_api_charge_cc_simple():
Expand Down
5 changes: 3 additions & 2 deletions tests/test_snap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from .config import USED_SERVER_KEY, USED_CLIENT_KEY
from .helpers import is_str
from .context import midtransclient
import datetime
Expand Down Expand Up @@ -120,8 +121,8 @@ def test_snap_create_transaction_min_with_custom_headers_via_setter():
# ======== HELPER FUNCTIONS BELOW ======== #
def generate_snap_instance():
snap = midtransclient.Snap(is_production=False,
server_key='SB-Mid-server-GwUP_WGbJPXsDzsNEBRs8IYA',
client_key='SB-Mid-client-61XuGAwQ8Bj8LxSS')
server_key=USED_SERVER_KEY,
client_key=USED_CLIENT_KEY)
return snap

def generate_param_min():
Expand Down

0 comments on commit 3c482b8

Please sign in to comment.