From cecf0bec9de2dcd176fc632e8a5348ab2f491cbe Mon Sep 17 00:00:00 2001 From: David Date: Mon, 16 Sep 2024 21:36:34 +0200 Subject: [PATCH] style: ruff format --- .../braintree_settings/braintree_settings.py | 4 +- .../doctype/gocardless_settings/__init__.py | 2 +- .../gocardless_settings.py | 2 +- .../doctype/mpesa_settings/mpesa_settings.py | 6 +-- .../paypal_settings/paypal_settings.py | 4 +- .../doctype/paytm_settings/paytm_settings.py | 2 +- .../razorpay_settings/razorpay_settings.py | 8 ++-- .../stripe_settings/stripe_settings.py | 45 ++++++++++--------- payments/templates/pages/payment_success.py | 1 - 9 files changed, 38 insertions(+), 36 deletions(-) diff --git a/payments/payment_gateways/doctype/braintree_settings/braintree_settings.py b/payments/payment_gateways/doctype/braintree_settings/braintree_settings.py index 717443e8..5c0fe801 100644 --- a/payments/payment_gateways/doctype/braintree_settings/braintree_settings.py +++ b/payments/payment_gateways/doctype/braintree_settings/braintree_settings.py @@ -14,7 +14,7 @@ class BraintreeSettings(Document): - supported_currencies = [ + supported_currencies = ( "AED", "AMD", "AOA", @@ -150,7 +150,7 @@ class BraintreeSettings(Document): "ZAR", "ZMK", "ZWD", - ] + ) def validate(self): if not self.flags.ignore_mandatory: diff --git a/payments/payment_gateways/doctype/gocardless_settings/__init__.py b/payments/payment_gateways/doctype/gocardless_settings/__init__.py index 65be5993..d8f8a3d3 100644 --- a/payments/payment_gateways/doctype/gocardless_settings/__init__.py +++ b/payments/payment_gateways/doctype/gocardless_settings/__init__.py @@ -34,7 +34,7 @@ def set_status(event): def set_mandate_status(event): mandates = [] - if isinstance(event["links"], (list,)): + if isinstance(event["links"], list): for link in event["links"]: mandates.append(link["mandate"]) else: diff --git a/payments/payment_gateways/doctype/gocardless_settings/gocardless_settings.py b/payments/payment_gateways/doctype/gocardless_settings/gocardless_settings.py index 1bc384a2..4abb7e97 100644 --- a/payments/payment_gateways/doctype/gocardless_settings/gocardless_settings.py +++ b/payments/payment_gateways/doctype/gocardless_settings/gocardless_settings.py @@ -13,7 +13,7 @@ class GoCardlessSettings(Document): - supported_currencies = ["EUR", "DKK", "GBP", "SEK", "AUD", "NZD", "CAD", "USD"] + supported_currencies = ("EUR", "DKK", "GBP", "SEK", "AUD", "NZD", "CAD", "USD") def validate(self): self.initialize_client() diff --git a/payments/payment_gateways/doctype/mpesa_settings/mpesa_settings.py b/payments/payment_gateways/doctype/mpesa_settings/mpesa_settings.py index 37ed9a52..97e9aacc 100644 --- a/payments/payment_gateways/doctype/mpesa_settings/mpesa_settings.py +++ b/payments/payment_gateways/doctype/mpesa_settings/mpesa_settings.py @@ -18,7 +18,7 @@ class MpesaSettings(Document): - supported_currencies = ["KES"] + supported_currencies = ("KES",) def validate_transaction_currency(self, currency): if currency not in self.supported_currencies: @@ -51,7 +51,7 @@ def request_for_payment(self, **kwargs): args = frappe._dict(kwargs) request_amounts = self.split_request_amount_according_to_transaction_limit(args) - for i, amount in enumerate(request_amounts): + for _i, amount in enumerate(request_amounts): args.request_amount = amount if frappe.flags.in_test: from payments.payment_gateways.doctype.mpesa_settings.test_mpesa_settings import ( @@ -197,7 +197,7 @@ def verify_transaction(**kwargs): ) total_paid = amount + sum(completed_payments) - mpesa_receipts = ", ".join(mpesa_receipts + [mpesa_receipt]) + mpesa_receipts = ", ".join([*mpesa_receipts, mpesa_receipt]) if total_paid >= pr.grand_total: pr.run_method("on_payment_authorized", "Completed") diff --git a/payments/payment_gateways/doctype/paypal_settings/paypal_settings.py b/payments/payment_gateways/doctype/paypal_settings/paypal_settings.py index eb27db8a..5bf4a2fb 100644 --- a/payments/payment_gateways/doctype/paypal_settings/paypal_settings.py +++ b/payments/payment_gateways/doctype/paypal_settings/paypal_settings.py @@ -79,7 +79,7 @@ def on_payment_authorized(payment_status): class PayPalSettings(Document): - supported_currencies = [ + supported_currencies = ( "AUD", "BRL", "CAD", @@ -105,7 +105,7 @@ class PayPalSettings(Document): "THB", "TRY", "USD", - ] + ) def __setup__(self): self.use_sandbox = 0 diff --git a/payments/payment_gateways/doctype/paytm_settings/paytm_settings.py b/payments/payment_gateways/doctype/paytm_settings/paytm_settings.py index a51ddb32..db879255 100644 --- a/payments/payment_gateways/doctype/paytm_settings/paytm_settings.py +++ b/payments/payment_gateways/doctype/paytm_settings/paytm_settings.py @@ -24,7 +24,7 @@ class PaytmSettings(Document): - supported_currencies = ["INR"] + supported_currencies = ("INR",) def validate(self): create_payment_gateway("Paytm") diff --git a/payments/payment_gateways/doctype/razorpay_settings/razorpay_settings.py b/payments/payment_gateways/doctype/razorpay_settings/razorpay_settings.py index a43fedd1..7394456f 100644 --- a/payments/payment_gateways/doctype/razorpay_settings/razorpay_settings.py +++ b/payments/payment_gateways/doctype/razorpay_settings/razorpay_settings.py @@ -79,7 +79,7 @@ def on_payment_authorized(payment_status): class RazorpaySettings(Document): - supported_currencies = ["INR"] + supported_currencies = ("INR",) def init_client(self): if self.api_key: @@ -251,8 +251,8 @@ def create_request(self, data): def authorize_payment(self): """ - An authorization is performed when user’s payment details are successfully authenticated by the bank. - The money is deducted from the customer’s account, but will not be transferred to the merchant’s account + An authorization is performed when user's payment details are successfully authenticated by the bank. + The money is deducted from the customer's account, but will not be transferred to the merchant's account until it is explicitly captured by merchant. """ data = json.loads(self.integration_request.data) @@ -341,7 +341,7 @@ def cancel_subscription(self, subscription_id): settings = self.get_settings({}) try: - resp = make_post_request( + make_post_request( f"https://api.razorpay.com/v1/subscriptions/{subscription_id}/cancel", auth=(settings.api_key, settings.api_secret), ) diff --git a/payments/payment_gateways/doctype/stripe_settings/stripe_settings.py b/payments/payment_gateways/doctype/stripe_settings/stripe_settings.py index 88b54137..ce3a1a02 100644 --- a/payments/payment_gateways/doctype/stripe_settings/stripe_settings.py +++ b/payments/payment_gateways/doctype/stripe_settings/stripe_settings.py @@ -1,6 +1,7 @@ # Copyright (c) 2017, Frappe Technologies and contributors # License: MIT. See LICENSE +from types import MappingProxyType from urllib.parse import urlencode import frappe @@ -11,9 +12,27 @@ from payments.utils import create_payment_gateway +currency_wise_minimum_charge_amount = { + "JPY": 50, + "MXN": 10, + "DKK": 2.50, + "HKD": 4.00, + "NOK": 3.00, + "SEK": 3.00, + "USD": 0.50, + "AUD": 0.50, + "BRL": 0.50, + "CAD": 0.50, + "CHF": 0.50, + "EUR": 0.50, + "GBP": 0.30, + "NZD": 0.50, + "SGD": 0.50, +} + class StripeSettings(Document): - supported_currencies = [ + supported_currencies = ( "AED", "ALL", "ANG", @@ -128,25 +147,9 @@ class StripeSettings(Document): "XPF", "YER", "ZAR", - ] - - currency_wise_minimum_charge_amount = { - "JPY": 50, - "MXN": 10, - "DKK": 2.50, - "HKD": 4.00, - "NOK": 3.00, - "SEK": 3.00, - "USD": 0.50, - "AUD": 0.50, - "BRL": 0.50, - "CAD": 0.50, - "CHF": 0.50, - "EUR": 0.50, - "GBP": 0.30, - "NZD": 0.50, - "SGD": 0.50, - } + ) + + currency_wise_minimum_charge_amount = MappingProxyType(currency_wise_minimum_charge_amount) def on_update(self): create_payment_gateway( @@ -225,7 +228,7 @@ def create_charge_on_stripe(self): receipt_email=self.data.payer_email, ) - if charge.captured == True: + if charge.captured is True: self.integration_request.db_set("status", "Completed", update_modified=False) self.flags.status_changed_to = "Completed" diff --git a/payments/templates/pages/payment_success.py b/payments/templates/pages/payment_success.py index 8985850a..e2d1115b 100644 --- a/payments/templates/pages/payment_success.py +++ b/payments/templates/pages/payment_success.py @@ -7,7 +7,6 @@ def get_context(context): - token = frappe.local.form_dict.token doc = frappe.get_doc(frappe.local.form_dict.doctype, frappe.local.form_dict.docname) context.payment_message = ""