refactor: clean up code to py39+ supported syntax - f-strings instead of format - latest typing support instead of pre 3.9 TitleCase - remove UTF-8 declarations. - many more changes Powered by https://github.com/asottile/pyupgrade/ + manual cleanupspull/2/head
@@ -1,4 +1,3 @@ | |||||
# -*- coding: utf-8 -*- | |||||
# Copyright (c) 2018, Frappe Technologies and contributors | # Copyright (c) 2018, Frappe Technologies and contributors | ||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
@@ -184,7 +183,7 @@ class BraintreeSettings(Document): | |||||
) | ) | ||||
def get_payment_url(self, **kwargs): | def get_payment_url(self, **kwargs): | ||||
return get_url("./integrations/braintree_checkout?{0}".format(urlencode(kwargs))) | |||||
return get_url(f"./integrations/braintree_checkout?{urlencode(kwargs)}") | |||||
def create_payment_request(self, data): | def create_payment_request(self, data): | ||||
self.data = frappe._dict(data) | self.data = frappe._dict(data) | ||||
@@ -1,4 +1,3 @@ | |||||
# -*- coding: utf-8 -*- | |||||
# Copyright (c) 2018, Frappe Technologies and Contributors | # Copyright (c) 2018, Frappe Technologies and Contributors | ||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
import unittest | import unittest | ||||
@@ -1,4 +1,3 @@ | |||||
# -*- coding: utf-8 -*- | |||||
# Copyright (c) 2015, Frappe Technologies and contributors | # Copyright (c) 2015, Frappe Technologies and contributors | ||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
@@ -193,7 +192,7 @@ class PayPalSettings(Document): | |||||
params.update( | params.update( | ||||
{ | { | ||||
"METHOD": "SetExpressCheckout", | "METHOD": "SetExpressCheckout", | ||||
"returnUrl": get_url("{0}.get_express_checkout_details".format(api_path)), | |||||
"returnUrl": get_url(f"{api_path}.get_express_checkout_details"), | |||||
"cancelUrl": get_url("/payment-cancel"), | "cancelUrl": get_url("/payment-cancel"), | ||||
"PAYMENTREQUEST_0_PAYMENTACTION": "SALE", | "PAYMENTREQUEST_0_PAYMENTACTION": "SALE", | ||||
"PAYMENTREQUEST_0_AMT": kwargs["amount"], | "PAYMENTREQUEST_0_AMT": kwargs["amount"], | ||||
@@ -331,7 +330,7 @@ def confirm_payment(token): | |||||
).run_method("on_payment_authorized", "Completed") | ).run_method("on_payment_authorized", "Completed") | ||||
frappe.db.commit() | frappe.db.commit() | ||||
redirect_url = "/integrations/payment-success?doctype={0}&docname={1}".format( | |||||
redirect_url = "/integrations/payment-success?doctype={}&docname={}".format( | |||||
data.get("reference_doctype"), data.get("reference_docname") | data.get("reference_doctype"), data.get("reference_docname") | ||||
) | ) | ||||
else: | else: | ||||
@@ -404,7 +403,7 @@ def create_recurring_profile(token, payerid): | |||||
).run_method("on_payment_authorized", status_changed_to) | ).run_method("on_payment_authorized", status_changed_to) | ||||
frappe.db.commit() | frappe.db.commit() | ||||
redirect_url = "/integrations/payment-success?doctype={0}&docname={1}".format( | |||||
redirect_url = "/integrations/payment-success?doctype={}&docname={}".format( | |||||
data.get("reference_doctype"), data.get("reference_docname") | data.get("reference_doctype"), data.get("reference_docname") | ||||
) | ) | ||||
else: | else: | ||||
@@ -427,11 +426,9 @@ def get_redirect_uri(doc, token, payerid): | |||||
data = json.loads(doc.data) | data = json.loads(doc.data) | ||||
if data.get("subscription_details") or data.get("subscription_id"): | if data.get("subscription_details") or data.get("subscription_id"): | ||||
return get_url( | |||||
"{0}.create_recurring_profile?token={1}&payerid={2}".format(api_path, token, payerid) | |||||
) | |||||
return get_url(f"{api_path}.create_recurring_profile?token={token}&payerid={payerid}") | |||||
else: | else: | ||||
return get_url("{0}.confirm_payment?token={1}".format(api_path, token)) | |||||
return get_url(f"{api_path}.confirm_payment?token={token}") | |||||
def manage_recurring_payment_profile_status(profile_id, action, args, url): | def manage_recurring_payment_profile_status(profile_id, action, args, url): | ||||
@@ -474,7 +471,7 @@ def ipn_handler(): | |||||
queue="long", | queue="long", | ||||
timeout=600, | timeout=600, | ||||
is_async=True, | is_async=True, | ||||
**{"doctype": "Integration Request", "docname": doc.name} | |||||
**{"doctype": "Integration Request", "docname": doc.name}, | |||||
) | ) | ||||
except frappe.InvalidStatusError: | except frappe.InvalidStatusError: | ||||
@@ -1,4 +1,3 @@ | |||||
# -*- coding: utf-8 -*- | |||||
# Copyright (c) 2020, Frappe Technologies and contributors | # Copyright (c) 2020, Frappe Technologies and contributors | ||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
@@ -37,7 +36,7 @@ class PaytmSettings(Document): | |||||
integration_request = create_request_log(kwargs, service_name="Paytm") | integration_request = create_request_log(kwargs, service_name="Paytm") | ||||
kwargs.update(dict(order_id=integration_request.name)) | kwargs.update(dict(order_id=integration_request.name)) | ||||
return get_url("./integrations/paytm_checkout?{0}".format(urlencode(kwargs))) | |||||
return get_url(f"./integrations/paytm_checkout?{urlencode(kwargs)}") | |||||
def get_paytm_config(): | def get_paytm_config(): | ||||
@@ -1,4 +1,3 @@ | |||||
# -*- coding: utf-8 -*- | |||||
# Copyright (c) 2020, Frappe Technologies and Contributors | # Copyright (c) 2020, Frappe Technologies and Contributors | ||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
# import frappe | # import frappe | ||||
@@ -1,4 +1,3 @@ | |||||
# -*- coding: utf-8 -*- | |||||
# Copyright (c) 2015, Frappe Technologies and contributors | # Copyright (c) 2015, Frappe Technologies and contributors | ||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
@@ -124,9 +123,7 @@ class RazorpaySettings(Document): | |||||
"quantity": 1 (The total amount is calculated as item.amount * quantity) | "quantity": 1 (The total amount is calculated as item.amount * quantity) | ||||
} | } | ||||
""" | """ | ||||
url = "https://api.razorpay.com/v1/subscriptions/{0}/addons".format( | |||||
kwargs.get("subscription_id") | |||||
) | |||||
url = "https://api.razorpay.com/v1/subscriptions/{}/addons".format(kwargs.get("subscription_id")) | |||||
try: | try: | ||||
if not frappe.conf.converted_rupee_to_paisa: | if not frappe.conf.converted_rupee_to_paisa: | ||||
@@ -195,7 +192,7 @@ class RazorpaySettings(Document): | |||||
def get_payment_url(self, **kwargs): | def get_payment_url(self, **kwargs): | ||||
integration_request = create_request_log(kwargs, service_name="Razorpay") | integration_request = create_request_log(kwargs, service_name="Razorpay") | ||||
return get_url("./integrations/razorpay_checkout?token={0}".format(integration_request.name)) | |||||
return get_url(f"./integrations/razorpay_checkout?token={integration_request.name}") | |||||
def create_order(self, **kwargs): | def create_order(self, **kwargs): | ||||
# Creating Orders https://razorpay.com/docs/api/orders/ | # Creating Orders https://razorpay.com/docs/api/orders/ | ||||
@@ -257,7 +254,7 @@ class RazorpaySettings(Document): | |||||
try: | try: | ||||
resp = make_get_request( | resp = make_get_request( | ||||
"https://api.razorpay.com/v1/payments/{0}".format(self.data.razorpay_payment_id), | |||||
f"https://api.razorpay.com/v1/payments/{self.data.razorpay_payment_id}", | |||||
auth=(settings.api_key, settings.api_secret), | auth=(settings.api_key, settings.api_secret), | ||||
) | ) | ||||
@@ -303,7 +300,7 @@ class RazorpaySettings(Document): | |||||
if custom_redirect_to: | if custom_redirect_to: | ||||
redirect_to = custom_redirect_to | redirect_to = custom_redirect_to | ||||
redirect_url = "payment-success?doctype={0}&docname={1}".format( | |||||
redirect_url = "payment-success?doctype={}&docname={}".format( | |||||
self.data.reference_doctype, self.data.reference_docname | self.data.reference_doctype, self.data.reference_docname | ||||
) | ) | ||||
else: | else: | ||||
@@ -339,7 +336,7 @@ class RazorpaySettings(Document): | |||||
try: | try: | ||||
resp = make_post_request( | resp = make_post_request( | ||||
"https://api.razorpay.com/v1/subscriptions/{0}/cancel".format(subscription_id), | |||||
f"https://api.razorpay.com/v1/subscriptions/{subscription_id}/cancel", | |||||
auth=(settings.api_key, settings.api_secret), | auth=(settings.api_key, settings.api_secret), | ||||
) | ) | ||||
except Exception: | except Exception: | ||||
@@ -383,14 +380,14 @@ def capture_payment(is_sandbox=False, sanbox_response=None): | |||||
settings = controller.get_settings(data) | settings = controller.get_settings(data) | ||||
resp = make_get_request( | resp = make_get_request( | ||||
"https://api.razorpay.com/v1/payments/{0}".format(data.get("razorpay_payment_id")), | |||||
"https://api.razorpay.com/v1/payments/{}".format(data.get("razorpay_payment_id")), | |||||
auth=(settings.api_key, settings.api_secret), | auth=(settings.api_key, settings.api_secret), | ||||
data={"amount": data.get("amount")}, | data={"amount": data.get("amount")}, | ||||
) | ) | ||||
if resp.get("status") == "authorized": | if resp.get("status") == "authorized": | ||||
resp = make_post_request( | resp = make_post_request( | ||||
"https://api.razorpay.com/v1/payments/{0}/capture".format(data.get("razorpay_payment_id")), | |||||
"https://api.razorpay.com/v1/payments/{}/capture".format(data.get("razorpay_payment_id")), | |||||
auth=(settings.api_key, settings.api_secret), | auth=(settings.api_key, settings.api_secret), | ||||
data={"amount": data.get("amount")}, | data={"amount": data.get("amount")}, | ||||
) | ) | ||||
@@ -403,7 +400,7 @@ def capture_payment(is_sandbox=False, sanbox_response=None): | |||||
doc.status = "Failed" | doc.status = "Failed" | ||||
doc.error = frappe.get_traceback() | doc.error = frappe.get_traceback() | ||||
doc.save() | doc.save() | ||||
frappe.log_error(doc.error, "{0} Failed".format(doc.name)) | |||||
frappe.log_error(doc.error, f"{doc.name} Failed") | |||||
@frappe.whitelist(allow_guest=True) | @frappe.whitelist(allow_guest=True) | ||||
@@ -498,7 +495,7 @@ def razorpay_subscription_callback(): | |||||
queue="long", | queue="long", | ||||
timeout=600, | timeout=600, | ||||
is_async=True, | is_async=True, | ||||
**{"doctype": "Integration Request", "docname": doc.name} | |||||
**{"doctype": "Integration Request", "docname": doc.name}, | |||||
) | ) | ||||
except frappe.InvalidStatusError: | except frappe.InvalidStatusError: | ||||
@@ -521,7 +518,7 @@ def validate_payment_callback(data): | |||||
settings = controller.get_settings(data) | settings = controller.get_settings(data) | ||||
resp = make_get_request( | resp = make_get_request( | ||||
"https://api.razorpay.com/v1/subscriptions/{0}".format(subscription_id), | |||||
f"https://api.razorpay.com/v1/subscriptions/{subscription_id}", | |||||
auth=(settings.api_key, settings.api_secret), | auth=(settings.api_key, settings.api_secret), | ||||
) | ) | ||||
@@ -1,4 +1,3 @@ | |||||
# -*- coding: utf-8 -*- | |||||
# Copyright (c) 2017, Frappe Technologies and contributors | # Copyright (c) 2017, Frappe Technologies and contributors | ||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
@@ -163,7 +162,7 @@ class StripeSettings(Document): | |||||
def validate_stripe_credentails(self): | def validate_stripe_credentails(self): | ||||
if self.publishable_key and self.secret_key: | if self.publishable_key and self.secret_key: | ||||
header = { | header = { | ||||
"Authorization": "Bearer {0}".format( | |||||
"Authorization": "Bearer {}".format( | |||||
self.get_password(fieldname="secret_key", raise_exception=False) | self.get_password(fieldname="secret_key", raise_exception=False) | ||||
) | ) | ||||
} | } | ||||
@@ -190,7 +189,7 @@ class StripeSettings(Document): | |||||
) | ) | ||||
def get_payment_url(self, **kwargs): | def get_payment_url(self, **kwargs): | ||||
return get_url("./integrations/stripe_checkout?{0}".format(urlencode(kwargs))) | |||||
return get_url(f"./integrations/stripe_checkout?{urlencode(kwargs)}") | |||||
def create_request(self, data): | def create_request(self, data): | ||||
import stripe | import stripe | ||||
@@ -1,4 +1,3 @@ | |||||
# -*- coding: utf-8 -*- | |||||
# Copyright (c) 2018, Frappe Technologies and Contributors | # Copyright (c) 2018, Frappe Technologies and Contributors | ||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
import unittest | import unittest | ||||
@@ -1,4 +1,3 @@ | |||||
# -*- coding: utf-8 -*- | |||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors | ||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
@@ -1,4 +1,3 @@ | |||||
# -*- coding: utf-8 -*- | |||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors | ||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
import unittest | import unittest | ||||