Sfoglia il codice sorgente

Provision to cancel existing subscription

pull/2/head
Saurabh 6 anni fa
parent
commit
19df9a9da3
2 ha cambiato i file con 33 aggiunte e 0 eliminazioni
  1. +22
    -0
      payments/payment_gateways/doctype/paypal_settings/paypal_settings.py
  2. +11
    -0
      payments/payment_gateways/doctype/razorpay_settings/razorpay_settings.py

+ 22
- 0
payments/payment_gateways/doctype/paypal_settings/paypal_settings.py Vedi File

@@ -177,6 +177,26 @@ class PayPalSettings(Document):
frappe.throw(_("Looks like something is wrong with this site's Paypal configuration.")) frappe.throw(_("Looks like something is wrong with this site's Paypal configuration."))


return response return response
def cancel_recurring_profile(self, **kwargs):
params, url = self.get_paypal_params_and_url()

if not kwargs.get('profile_id'):
frappe.throw(_("PayPal Recurring Profile ID is required"))

params.update({
"METHOD": "ManageRecurringPaymentsProfileStatus",
"PROFILEID": kwargs['profile_id'],
"ACTION": "Cancel"
})

params = urlencode(params)

response = make_post_request(url, data=params.encode("utf-8"))
if response.get("ACK")[0] != "Success":
frappe.throw(_("Looks like something is wrong with this site's Paypal configuration."))

return response


@frappe.whitelist(allow_guest=True, xss_safe=True) @frappe.whitelist(allow_guest=True, xss_safe=True)
def get_express_checkout_details(token): def get_express_checkout_details(token):
@@ -316,6 +336,8 @@ def create_recurring_profile(token, payerid):
}, "Completed") }, "Completed")


if data.get("reference_doctype") and data.get("reference_docname"): if data.get("reference_doctype") and data.get("reference_docname"):
data['subscription_details']['subscription_id'] = response.get("PROFILEID")[0]

frappe.flags.data = data frappe.flags.data = data
custom_redirect_to = frappe.get_doc(data.get("reference_doctype"), custom_redirect_to = frappe.get_doc(data.get("reference_doctype"),
data.get("reference_docname")).run_method("on_payment_authorized", "Completed") data.get("reference_docname")).run_method("on_payment_authorized", "Completed")


+ 11
- 0
payments/payment_gateways/doctype/razorpay_settings/razorpay_settings.py Vedi File

@@ -258,6 +258,17 @@ class RazorpaySettings(Document):
}) })


return settings return settings
def cancel_subscription(self, subscription_id):
settings = self.get_settings()
try:
resp = make_get_request("https://api.razorpay.com/v1/subscriptions/{0}/cancel"
.format(subscription_id), auth=(settings.api_key,
settings.api_secret))
except Exception:
frappe.log_error(frappe.get_traceback())


def capture_payment(is_sandbox=False, sanbox_response=None): def capture_payment(is_sandbox=False, sanbox_response=None):
""" """


Caricamento…
Annulla
Salva