Skip to content

Commit

Permalink
Merge pull request #100 from pateljannat/stripe-checkout-issue
Browse files Browse the repository at this point in the history
fix: stripe checkout
  • Loading branch information
pateljannat authored Sep 30, 2024
2 parents f84edf9 + e8f3fa1 commit 1e58f5a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ jobs:

- name: Run Semgrep rules
run: |
pip install semgrep==0.97.0
pip install semgrep==1.90.0
semgrep ci --config ./frappe-semgrep-rules/rules --config r/python.lang.correctness
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ def finalize_request(self):
return {"redirect_to": redirect_url, "status": status}


def get_gateway_controller(doctype, docname):
reference_doc = frappe.get_doc(doctype, docname)
gateway_controller = frappe.db.get_value(
"Payment Gateway", reference_doc.payment_gateway, "gateway_controller"
)
def get_gateway_controller(doctype, docname, payment_gateway=None):
if not payment_gateway:
reference_doc = frappe.get_doc(doctype, docname)
payment_gateway = reference_doc.payment_gateway
gateway_controller = frappe.db.get_value("Payment Gateway", payment_gateway, "gateway_controller")
return gateway_controller
3 changes: 2 additions & 1 deletion payments/templates/includes/stripe_checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function setOutcome(result) {
"stripe_token_id": result.token.id,
"data": JSON.stringify({{ frappe.form_dict|json }}),
"reference_doctype": "{{ reference_doctype }}",
"reference_docname": "{{ reference_docname }}"
"reference_docname": "{{ reference_docname }}",
"payment_gateway": "{{ payment_gateway }}"
},
callback: function(r) {
if (r.message.status == "Completed") {
Expand Down
13 changes: 8 additions & 5 deletions payments/templates/pages/stripe_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"reference_docname",
"payer_name",
"payer_email",
"order_id",
"currency",
"payment_gateway",
)


Expand All @@ -32,8 +32,9 @@ def get_context(context):
if not (set(expected_keys) - set(list(frappe.form_dict))):
for key in expected_keys:
context[key] = frappe.form_dict[key]

gateway_controller = get_gateway_controller(context.reference_doctype, context.reference_docname)
gateway_controller = get_gateway_controller(
context.reference_doctype, context.reference_docname, context.payment_gateway
)
context.publishable_key = get_api_key(context.reference_docname, gateway_controller)
context.image = get_header_image(context.reference_docname, gateway_controller)

Expand Down Expand Up @@ -71,12 +72,14 @@ def get_header_image(doc, gateway_controller):


@frappe.whitelist(allow_guest=True)
def make_payment(stripe_token_id, data, reference_doctype=None, reference_docname=None):
def make_payment(
stripe_token_id, data, reference_doctype=None, reference_docname=None, payment_gateway=None
):
data = json.loads(data)

data.update({"stripe_token_id": stripe_token_id})

gateway_controller = get_gateway_controller(reference_doctype, reference_docname)
gateway_controller = get_gateway_controller(reference_doctype, reference_docname, payment_gateway)

if is_a_subscription(reference_doctype, reference_docname):
reference = frappe.get_doc(reference_doctype, reference_docname)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ readme = "README.md"
dynamic = ["version"]
dependencies = [
"paytmchecksum~=1.7.0",
"razorpay~=1.2.0",
"stripe~=2.56.0",
"razorpay~=1.4.2",
"stripe~=10.12.0",
"braintree~=4.20.0",
"pycryptodome>=3.18.0,<4.0.0",
"gocardless-pro~=1.22.0",
Expand Down

0 comments on commit 1e58f5a

Please sign in to comment.