Hi,
I am trying Payments Integration Via React.
In front end i am using this code. This is giving stripe Id.
Front end code:
setLoading(true);
setError("");
if (!stripe || !card) {
setError("Stripe is not initialized");
setLoading(false);
return;
}
try {
const result = await stripe.createToken(card, {
name: formData.cardholder_name,
email: formData.cardholder_email,
});
console.log("stripe-result", result);
if (result.error) {
setError(result.error.message);
} else if (result.token) {
const response = await fetch(
"/api/method/turiya_app.api.make_payment",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
stripe_token_id: result.token.id,
data: JSON.stringify(formData),
// reference_doctype: "Payment Gateway", // Replace with your reference doctype
// reference_docname: "Stripe-Stripe Test", // Replace with your reference docname
}),
}
);
if (response.ok) {
const data = await response.json();
if (data.status === "Completed") {
console.log("Payment successful");
} else {
console.error("Payment failed");
}
} else {
console.error("Error making payment");
}
}
} catch (error) {
console.error("Stripe token creation error:", error);
setError(
"An error occurred during payment processing. Please try again."
);
} finally {
setLoading(false);
}
};
Which doctype i need to mention Stripe Settings is already available in doctype i mentioned that once.
i created a Stripe Test in Stripe Setting which is having my api key and secret.
In Payment Gateway Doctype List
I have Stripe-Stripe Test
it has connected with
Gateway Settings - Stripe Settings
Gateway Controller - Stripe Test
I copied the api from payments app and moved to my app, api.py
My python code:
@frappe.whitelist(allow_guest=True)
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"
)
return gateway_controller
@frappe.whitelist(allow_guest=True)
def make_payment(stripe_token_id, data, reference_doctype="Payment Gateway", reference_docname="Stripe-Stripe Test"):
data = json.loads(data)
frappe.log_error("data_error", data)
data.update({"stripe_token_id": stripe_token_id})
frappe.log_error("data", data)
gateway_controller = get_gateway_controller(reference_doctype, reference_docname)
frappe.log_error("gateway_controller", gateway_controller)
if is_a_subscription(reference_doctype, reference_docname):
reference = frappe.get_doc(reference_doctype, reference_docname)
frappe.log_error("reference", reference)
data = reference.create_subscription("stripe", gateway_controller, data)
frappe.log_error("data2", data)
else:
data = frappe.get_doc("Stripe Settings", gateway_controller).create_request(data)
frappe.log_error("data3", data)
frappe.db.commit()
return data
I am getting this error how to solve and make it work help please
or can we call the payments app from react ???
{exception: "AttributeError: 'PaymentGateway' object has no attribute 'payment_gateway'",…}
exc
:
"[\"Traceback (most recent call last):\\n File \\\"apps/frappe/frappe/app.py\\\", line 53, in application\\n response = frappe.api.handle()\\n File \\\"apps/frappe/frappe/api.py\\\", line 53, in handle\\n return _RESTAPIHandler(call, doctype, name).get_response()\\n File \\\"apps/frappe/frappe/api.py\\\", line 69, in get_response\\n return self.handle_method()\\n File \\\"apps/frappe/frappe/api.py\\\", line 79, in handle_method\\n return frappe.handler.handle()\\n File \\\"apps/frappe/frappe/handler.py\\\", line 48, in handle\\n data = execute_cmd(cmd)\\n File \\\"apps/frappe/frappe/handler.py\\\", line 86, in execute_cmd\\n return frappe.call(method, **frappe.form_dict)\\n File \\\"apps/frappe/frappe/__init__.py\\\", line 1591, in call\\n return fn(*args, **newargs)\\n File \\\"apps/frappe/frappe/utils/typing_validations.py\\\", line 33, in wrapper\\n return func(*args, **kwargs)\\n File \\\"apps/turiya_app/turiya_app/api.py\\\", line 811, in make_payment\\n gateway_controller = get_gateway_controller(reference_doctype, reference_docname)\\n File \\\"apps/frappe/frappe/utils/typing_validations.py\\\", line 33, in wrapper\\n return func(*args, **kwargs)\\n File \\\"apps/turiya_app/turiya_app/api.py\\\", line 799, in get_gateway_controller\\n \\\"Payment Gateway\\\", reference_doc.payment_gateway, \\\"gateway_controller\\\"\\nAttributeError: 'PaymentGateway' object has no attribute 'payment_gateway'\\n\"]"
exception
:
"AttributeError: 'PaymentGateway' object has no attribute 'payment_gateway'"
_debug_messages
:
"[\"method:turiya_app.api.make_payment\"]"
Please take a look at this sir @buildwithhussain