瀏覽代碼

Provision to cancel existing subscription

pull/2/head
Saurabh 6 年之前
父節點
當前提交
19df9a9da3
共有 2 個文件被更改,包括 33 次插入0 次删除
  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 查看文件

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

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)
def get_express_checkout_details(token):
@@ -316,6 +336,8 @@ def create_recurring_profile(token, payerid):
}, "Completed")

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

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


+ 11
- 0
payments/payment_gateways/doctype/razorpay_settings/razorpay_settings.py 查看文件

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

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):
"""


Loading…
取消
儲存