Reputation: 86
I am trying to implement a model in which if a user pays for the first time he is registered with the subscription according to plan he selects.
I am using ReactJs as forntend and NodeJs as backend.
There are 2 issues that I am currently facing -
This is the Nodejs code for creating a subscription and returning subscriptionId for further process.
const plans = await instance.plans.all();
let i;
for (i = 0; i < plans.count; i++) {
if (plans.items[i].item.name === "Test plan - Weekly") break;
}
const planId = plans.items[i].id;
const subscriptionData = {
plan_id: planId,
total_count: 1,
quantity: 1,
customer_notify: 1,
};
const response = await instance.subscriptions.create(subscriptionData);
res.send(response.id);
This is my react code to open razorpay for payment. When this opens I do get an error in console, which is serviceworker must be a dictionary in your web app manifest.
Note - I have replaced key below due to security reasons.
axios.get("http://localhost:5000/razorpay").then((subscriptionId) => {
var options = {
key: "Test_Key",
subscription_id: subscriptionId,
name: "Consuma",
description: "Monthly Test Plan",
handler: function (response) {
console.log(response);
},
};
var razorpay = new window.Razorpay(options);
razorpay.open();
razorpay.on("payment.failed", function (response) {
alert(response.error.code);
alert(response.error.description);
alert(response.error.source);
alert(response.error.step);
alert(response.error.reason);
alert(response.error.metadata.order_id);
alert(response.error.metadata.payment_id);
});
});
I should expect razorpay_subscription_id and razorpay_signature for verification, but those fields are missing.
Below is the response that I get.
checkout_logo: "https://cdn.razorpay.com/logo.png"
custom_branding: false
org_logo: ""
org_name: "Razorpay Software Private Ltd"
razorpay_payment_id: "pay_HS0u4wIhrQavw
The plan that I used above is of Rs. 699 to be charged weekly, but while paying the amount I am only asked to pay Rs. 1. According to Razorpay documentation this rs 1 is an authorization from the user to subscribe to the plan and once this is successful, the plan amount will be deducted from users account as per the plan. But nothing such happens. Also, in the Razorpay dashboard this payment is considered as authorized and not as captured.
Upvotes: 1
Views: 960
Reputation: 86
So, the first issue was an error in code. I wasn't sending a correct subscription id and due to that I wasn't receiving any expected response.
As far as 'serviceworker' error is considered I received following response fro razorpay team.
Upvotes: 0