Skip to content

Commit

Permalink
Support for MBWay (#4)
Browse files Browse the repository at this point in the history
Support for MBWay using the customer field info.
  • Loading branch information
joamag authored Jan 1, 2025
1 parent 9d1d17c commit d391925
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

session.shelve*
easypay.shelve*
easypay_v2.shelve*

/.env
/.venv
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

*
* Support for MBWay payments - [#2](https://github.com/hivesolutions/easypay-api/issues/2)

### Changed

Expand Down
26 changes: 20 additions & 6 deletions src/easypay/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,18 @@
class PaymentAPI(object):

def generate_payment(
self, amount, method="mb", currency="EUR", key=None, warning=None, cancel=None
self,
amount,
method="mb",
currency="EUR",
key=None,
customer=None,
warning=None,
cancel=None,
):
result = self.create_payment(amount, method=method, currency=currency, key=key)
result = self.create_payment(
amount, method=method, currency=currency, key=key, customer=customer
)
status = result.get("status", "error")
if not status == "ok":
raise appier.OperationalError("Problem creating payment")
Expand All @@ -47,18 +56,23 @@ def generate_payment(
method["currency"] = currency
method["warning"] = warning
method["cancel"] = cancel
if not customer == None:
method["customer"] = customer
self.set_payment(method)
return method

def list_payments(self, *args, **kwargs):
url = self.base_url + "single"
return self.get(url, *args, **kwargs)

def create_payment(self, amount, method="mb", currency="EUR", key=None):
def create_payment(
self, amount, method="mb", currency="EUR", key=None, customer=None
):
url = self.base_url + "single"
return self.post(
url, data_j=dict(value=amount, method=method, currency=currency, key=key)
)
data_j = dict(value=amount, method=method, currency=currency, key=key)
if not customer == None:
data_j["customer"] = customer
return self.post(url, data_j=data_j)

def get_payment(self, id):
url = self.base_url + "single/%s" % id
Expand Down
9 changes: 8 additions & 1 deletion src/examples/app_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,17 @@ def create_payment(self):
amount = self.field("amount", 10, cast=float)
method = self.field("method", "mb")
key = self.field("key", None)
phone = self.field("phone", None)
warning = self.field("warning", None, cast=float)
cancel = self.field("cancel", None, cast=float)
customer = dict(phone=phone) if phone else None
return self.api.generate_payment(
amount=amount, method=method, key=key, warning=warning, cancel=cancel
amount=amount,
method=method,
key=key,
customer=customer,
warning=warning,
cancel=cancel,
)

@appier.route("/payments/show/<str:id>", "GET")
Expand Down

0 comments on commit d391925

Please sign in to comment.