Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for MBWay #4

Merged
merged 4 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
joamag marked this conversation as resolved.
Show resolved Hide resolved
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
Loading