Git Product home page Git Product logo

razorpay-node's Issues

Webhook proper example is missing

Have completed the webhook setup on the razorpay dashboard, then tried to catch the req object on my method, it shows nothing.

function PaymentCycleInfo(req, res) {
   console.log('payment');
    console.log(req);
    res.success("SXS32003");
}

fetch error in javascript and nodejs , but direct url working in browser and postman

Failed to load resource: the server responded with a status of 400 (Bad Request) localhost/:1 Access to fetch at 'https://api.razorpay.com/v1/payments/pay_D13Z7yMIvl0XXB' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Orders creation rejection issue

server code:

instance.orders.create({amount: 12 ,currency: 'INR',receipt:'12',payment_cature: 'true'},(err,res) => {
                           if(err) console.log("error");
                           else console.log("order created");
                         });

Response:
Unhandled rejection (<{"statusCode":400,"error":{"code":"BAD...>, no stack trace)

Handle when user is offline

When use is offline , promises are rejected with { statusCode: undefined, error: undefined } need to put appropriate message in there

Razorpay Split Payments API

Where is the Razorpay split payments / route api for nodejs?
It's not clear how is it different from normal razorpay APIs.

[Java] Integration capture payment giving an error

I am doing razorpay java API integration with spring boot.

Below is the razorpay version which I am using.

<dependency>
    <groupId>com.razorpay</groupId>
    <artifactId>razorpay-java</artifactId>
    <version>1.3.8</version>
</dependency>

Capture payment API is giving me an error.
Below code snippet which I am using to capture payment.

public static String capturePayment(String paymentid){
        try {
            JSONObject options = new JSONObject();
            options.put("amount", 500.00);
            CustomRazopayClient.getRazopayClient().Payments.capture(paymentid, options);
            return "success";
        }catch (Exception e){
            return e.getLocalizedMessage();
        }
    }

Error which I am getting
"BAD_REQUEST_ERROR:Capture amount must be equal to the amount authorized"

I have tried an amount as 500.
Can anyone help here?

control flow

Prologue

#19 defines an existing problem where the promise chain is broken on concurrent control flow types (Promises and callbacks).

Problem

Implementing both of them at once is a design flaw and it should be noted that Node dictates a strict choice between the two. (Look at request and its accompanying request-promise catalogue.)

Solution

A simple callback adapter can be placed and since the world is moving on to Promises, it would make for a sensible default. Then, on initialization, the following can be passed in the options object:

const Razorpay = require( 'razorpay-sdk' );
const apiObject = new Razorpay( { controlFlow: 'callbacks' } );

Tags

Enhancements, broken, bugs

(Direct CC: @captn3m0)

resource testing

Prologue

The current test cases are not use cases or state-test cases but rather implementation tests; hence, it's neither the behavior we are testing nor the actual use case and this is a bad practice (you can read about implementation vs. state tests in a lovely article by Eric Elliot or Addy Osmani.)

Because of this, the tests are really bloated (at around 190 cases in total.)

Solution

The current test bed should be rewritten to include the states of the object instead of their mutations (checking the reply as opposed to the URL.)

Tags

suggestion, testing, improvement, dev.

How to send currency filed in capture api?

Hi ,
I am using this piece of code

rzp.payments.capture(req.params.paymentId, req.body.amount,req.body.currency).then((data) => {
  // success
    return res.status(200).json({status:true,details:data});
}).catch((error) => {
  // error
  console.log("Capture api error",error);
  return res.status(400).json({status:false,message:error.description});
})

When I am trying to send currency field I am getting error. I changed the capture method in node-modules folder.How can I solve this error? How can I send currency field during capture?

Payment capture not working on node but working on direct api call

Environment

node -v
v8.11.1

package.json

{
  "name": "<REDACTED>",
  "version": "1.0.1",
  "description": "<REDACTED>",
  "main": "app.js",
  "scripts": {
    "start": "node app"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.12.0",
    "cookie-parser": "^1.3.4",
    "express": "^4.12.1",
    "express-session": "^1.10.3",
    "jsonwebtoken": "^8.2.1",
    "mailgun-js": "^0.16.0",
    "nano": "^6.4.2",
    "passport": "^0.2.1",
    "passport-http-bearer": "^1.0.1",
    "passport-jwt": "^4.0.0",
    "passport-local": "^1.0.0",
    "path": "^0.12.7",
    "q": "^1.4.1",
    "razorpay": "^1.7.1",
    "request": "^2.55.0"
  }
}

Code

This is the code I'm using

var instanceRazorpay = new Razorpay({
                                        key_id    : '<REDACTED>',
                                        key_secret: '<REDACTED>'
                                      });

  //capture payment
  //make amount dynamic if its going to keep changing; suggestion: verify amount from db or some trusted source
  instanceRazorpay.payments.capture(razorpay_payment_id, 10000)
                  .then((response) => {
                    // handle success
                    console.log('/razorpay/paymentCapture:', 'success:', 'razorpay_payment_id:', razorpay_payment_id);
                    // NOTE to future devs/Ramesh: add anything you want to do after successful payment here
                    res.send({isPaymentSuccessful: true});
                  }).catch((error) => {
    // NOTE to future devs/Ramesh: add anything you want to do after FAILED payment here
    // handle error
    console.error('/razorpay/paymentCapture', error);
    res.send({
               isPaymentSuccessful: false
               error              : error
             });
  });

This returns

/razorpay/paymentCapture { statusCode: 400,
  error: 
   { code: 'BAD_REQUEST_ERROR',
     description: 'The id provided does not exist' } }

However, it works when I directly call your capture api endpoint from postman.

I didn't get any other logs to add. Please ask me for further information if you need it

namespacing modules

Prologue

The current library contains exports for all possible resources supported by the Razorpay SDK. This is a tightly-coupled architecture and it should be noted that it adds a lot of weight to the process utilizing the resource.

Solution

The library should be namespaced based on the resources with one module being a wrapper around all of them.

For example, to use the payments resource:

const Payments = require( '@razorpay/payments' );
const apiObject = new Payments.extend( { ... } ); // or new Payments( { ... } );

Or to use the entire SDK:

const Razorpay = require( '@razorpay/sdk' );
const { Payments } = new Razorpay( { ... } );

Benefits

This will help the use decide exactly what they want to use and the test cases will be targeted specifically at the resource providing higher case testing as opposed to case coverage.

Meta Information

Implementation Time: 5 days
Implementation Complexity: Intermediate (or Easy)

Tags

suggestions, enhancements, documentation, testing, BREAKING CHANGE

In manual checkout handler function is not triggerred instead shows alert

Follwing the standard checkout manual process.

But the handler function doesn't get triggerred but instead response is shown in an alert window of the browser.

        handler: response => {
          debug("payment response", response);
        },

Even on successful test payment, handler is not triggerred but the Razopay checkout popup vainishes on clicking the Success button.

Screenshot from 2019-10-25 09-33-22

Screenshot from 2019-10-25 09-37-19

Unable to create a subscription

I've initiated Razorpay with my TEST key and secret.

Below is the code and error -

razorpay.subscriptions.create({
    "plan_id": PRO_PLAN_ID,
    "customer_notify": 1,
    "total_count": 1,
    "start_at": Date.now()
})
.then(subscription => {
    if (subscription) {
        return res.render('purchase', {subscription: subscription })
    } else {
        throw new Error('Invalid subscriptions')
    }
})
.catch(err => {
    return next(err)
})

Error

(node:10194) Warning: a promise was rejected with a non-error: [object Object]
// when i log the error -
{ statusCode: undefined, error: undefined }

My plan_id is valid and my subscriptions is enabled with Razorpay.

Absolutely unable to move forward. Can someone help? @rzpamidi ?

The server encountered an error. The incident has been reported to admins.

We are not able to work with the fund_accounts/validations api endpoint. It is throwing the below error :

{
"error": {
"code": "SERVER_ERROR",
"description": "The server encountered an error. The incident has been reported to admins."
}
}

The problem is not with the bank account data and API keys. What might be the reason ?

Order Creation failure

razorpayInstance.orders.create(data,(error, response) => {
if (error) {
// handle error
res.json({"success":false,"response":null});
console.log(error);
}else{
// handle success
res.json({"success":true,"response":response});
console.log(response);
}
});

This function is always going into timeout. It doesn't return anything.

Account onboarding via api

On the docs https://razorpay.com/docs/route/onboarding/ i see it is possible to onboard sellers via api.

To start moving funds to your seller accounts, you need to onboard your sellers to Razorpay Route first.
You can onboard these sellers on the Razorpay Dashboard or via our API.

But I don't find anything in the library or api docs about that api.

Unable to scroll EMI Plans.

Unable to scroll EMI Option While click on EMI Option from PG with Pay With EMI Buttons. Please check attached below screenshot for reference.
Device is iPhone 5SE.

image

Checkout flow implemented like licious.in

I am using razorpay checkout form in my web app. But I want the checkout flow like licious.in has implemented. As in you give them various options and take the details from them and redirect to razorpay server. I am using Nodejs.
It sounds naive. I would appreciate any suggestions

Integrate with test suite

We use Razorpay to handle all our payments at @tiltbike. In our local test suite written in Jest, I'm unable to test our mission critical payment functions due to the integration with Razorpay.

Is there any functionality similar to stripe-mock which can make testing with Razorpay in our server's test suite possible?

Razorpay.validateWebhookSignature() is not working for invoice.paid events.

Here is code snippet

    let body = req.body;
    let received_signature = req.get("x-razorpay-signature");
    let secret = "xxxx";

    var success = Razorpay.validateWebhookSignature(
      JSON.stringify(body),
      received_signature,
      secret
    );

Razorpay.validateWebhookSignature() returns true for other webhook events but for events type "invoice.type" it is returning false.

The id provided does not exist razorpay in nodejs

i'm implementing razorpay payment gateway in my React.js app with backend nodejs.

here frontend.jsx

razorpayHandler = () =>{
        const payment_amount  = this.props.TotalPrice;
        const backend_url = 'https://25234399bb.ngrok.io';
        const self = this;
        const options = {
        key: config.RAZOR_PAY_KEY,
        amount: payment_amount * 100,
        name: 'StanPlus',
        description: 'pay your ambulance fare',
        handler(response) {
            const paymentId = response.razorpay_payment_id;
            const url =  backend_url+'/razorpay/'+paymentId+'/'+payment_amount+'/'+self.id;
            console.log(paymentId)
            // Using my server endpoints to capture the payment
            fetch(url, {
            method: 'get',
            headers: {
                "Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
            }
            })
            .then(resp =>  resp.json())
            .then(function (data) {
                    console.log(data)
            })
            .catch(function (error) {
                console.log('Request failed', error);
            });
        },
        theme: {
            color: '#40A9FF',
        },
        };
        const rzp1 = new window.Razorpay(options);

        rzp1.open();
    }

backend.js(nodejs)

var express = require('express');
var router = express.Router();
var config = require('../config');

const Razorpay = require('razorpay');
const instance = new Razorpay({
  key_id: config.razorpay_live_key,
  key_secret: config.razorpay_live_secret,
});

router.get('/:payment_id/:amount/:BID',function(req,res,next){
    const {payment_id } = req.params;
    const {BID} = req.params;
    const amount = Number(req.params.amount*100);
    instance.payments.capture(payment_id, amount).then((data) => {
        data.Bid = BID;
        res.json(data);
    }).catch((error) => {
        res.json(error);
    });
})
module.exports = router;

it showing me error

"statusCode":400,"error":{"code":"BAD_REQUEST_ERROR","description":"The id provided does not exist"

but if the same code if do process using test key its getting successfully completed but it is not working with live api.

here i'm passing an extra parameter to the backend which required for us but if removed that parameter then also it is not working.but with parameter it is working with test api.

when we send request to backend it is generating id and sending to backend also but still it showing The id provided does not exist.

create plan and subscription not creat by api

var instance = new razorpay({
    key_id: 'XXXXXXXXXXXXXXXX',
    key_secret: 'XXXXXXXXXXXXXX'
  }) 
let params={
    "period": "weekly",
    "interval": 1,
    "item": {
      "name": "Test Weekly 1 plan",
      "description": "Description for the weekly 1 plan",
      "amount": 600,
      "currency": "INR"
    }
  }

 instance.plans.create(params).then((res)=>{
  // handle res
   }).catch((err)=>{
//  handle res
        )})
 }

gives error

{
    "error": {
        "code": "BAD_REQUEST_ERROR",
        "description": "The requested URL was not found on the server."
    }
}

The payment status should be captured for action to be taken

We are using checkout.js to process a payment.
After payment processing we are calling below function to transfer partial amount

instance.payments.transfer(paymentId, {
                transfers: [
                    {
                        account: accountId,
                        amount: amount,
                        currency: "INR"
                    }
                ]
            })

But this is giving below error

{ statusCode: 400,
  error: 
   { code: 'BAD_REQUEST_ERROR',
     description: 'The payment status should be captured for action to be taken' } }

Payment status is Authorized but not captured.
How to change payment status to captued through API?

Warnings during npm install

npm WARN prepublish-on-install As of npm@5, `prepublish` scripts are deprecated.
npm WARN prepublish-on-install Use `prepare` for build steps and `prepublishOnly` for upload-only.
npm WARN prepublish-on-install See the deprecation note in `npm help scripts` for more information.
npm WARN lifecycle [email protected]~prepublish: cannot run in wd %s %s (wd=%s) [email protected] npm test /root/razorpay-node
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

unable to capture payments made with test mode.

  1. I have made a test payment through browser.
  2. i could see that payment reflecting in dashboard.
  3. on nodejs server i have the following code to capture the payment made.
    `'use strict'

const Razorpay = require('razorpay')

let rzp = new Razorpay({
key_id: 'my key',
key_secret: 'my secret'
});

module.exports = function (app) {

app.route('/capturepayment')
//.all(app.authenticate.authenticate())
    .post(function (req, res) {
        const razorid = req.body['razorPaymentID'];
        const amount = req.body['amount'];
        rzp.payments.capture(razorid, amount).then((data) => {
            console.log('Payment successful');
            res.status(200);
        }).catch((error) => {
            console.log('Payment un-successful' + error.message);
            res.status(400);
        })

    })
    .get(function (req, res) {
        rzp.payments.all({
            from: 'Mar 31, 2017',
            to: 'Apr 1, 2017'
        }).then((data) => {
            console.log(data)
        }).catch((error) => {
            console.error(error)
        })
    });

};`
In both the get and post routes of my server it always goes to catch statement with out any error message.
Once on my console i have seen an error "un-handled promise rejection error". any help is appreciated.

Note: i could successfully capture the payment using postman and the direct url with same key and secret.

Missing APIs

The Fetch All Customers API and the entire Items API is missing in the node-sdk, please implement it soon as we have a requirement for the same in our application.

Understanding the payment states

Hi,
I understand this forum is for bugs and not knowledge sharing, but i have gone through almost all pages and got nothing, so lets treat this as a documentation bug, if u want to take it that way.

Scenario:
I am using google cloud functions to generate order ID, once id is generate i am making call to payment api (following standard checkout flow) and once order is completed i am trying to capture the payment, but it always throws error 'payment is already captured'

Now what i understood, if i am using order API, and going by above mentioned flow, i don't need to manually capture the payment, it's automatically captured. am i correct ?

Secondly, which state depicts my payment is completed as authorized, paid and captured all are not clear to me.

one complete flow example in nodejs would be a great help.

Not able to verify signature of payment

I have tried following code for verifying payment signature. But signature from payment and generated at my point are diffrent. Please let me know if i am doing something wrong here.
Additionally in docs, there's no sample code for nodejs. It will be really good if we can just find it there.

let generatedSignature = crypto
  .createHmac(
     "SHA256",
     "my-secret"
).update(payment.razorpay_payment_id + '|' + payment.razorpay_order_id)
.digest('hex');
let isSignatureValid = generatedSignature == payment.razorpay_signature;

Broken Promises Flow

Different behaviour has been noted with the promise returned, when a callback is passed to the api function.

eg.

const instance = new Razorpay({
  key_id: 'rzp_test_2mYdwI91aUdL2u',
  key_secret: 'hd0FgTKnZUUJCGYHTdfQ6Zx2'
});

instance.payments.all({})
  .then((arg) => console.log(arg)) // arg value is printed  
  .catch(arg => console.log(arg))

instance.payments.all({}, function () {
  console.log(arguments); // arguments are printed
}).then((arg) => console.log(arg)) // arg value is undefined 
  .catch(arg => console.log(arg))

How to get the payment ID in NodeJS for Orders API?

Hello,
I'm trying to do the payment through the Orders API.

   let razorpay = new Razorpay({
      key_id: outConfigs.razorpay.key_id,
      key_secret: outConfigs.razorpay.key_secret,
    });

    let output: any;

    await razorpay.orders.create({
      amount: data['amount'],
      currency: data['currency'],
      receipt: data['receipt'],
      payment_capture: data['payment_capture'],
      notes: data['notes']
    }).then(async (result) => {
      output = result;
      let payments = await razorpay.orders.fetchPayments(result.id);
      console.log(payments);
   }).catch((error) => {
        output = data;
   });

When I print the fetchPayments() it shows as follows:

{ entity: 'collection', count: 0, items: [] }

To proceed with payments I need to Payment_id but it returns the empty collection.

How do I proceed? Is there any step I'm missing?

Regards,
Saneesh.

Unable to capture payment

I am using version 1.2.0 and trying to make payment using instance.payments.capture, however it throws following error -

(node:5715) Warning: a promise was rejected with a non-error: [object Object]
{ statusCode: undefined, error: undefined }

If I check on the dashboard then under payments tab, I can see the payment getting authorised and using the same payment_id and amount (in paise) if I make the request, it still throws the same error. I have reset the API Key and Secret too before sending a fresh request. But no success. It would be great if at least proper error message is shown so that it will be easier to debug.

Let me know if you want any other details.

TypeError: rzp1.open is not a function

I am trying to integrate manual checkout. I have added checkout.js in the header of the html file. However, when I am trying to create the Razorpay object, it is showing undefined.
screen shot 2018-06-14 at 4 10 23 pm

while creating order getting error with undefined status and error

 var key_id = '##########';
  var key_secret = '##############';

  var instance = new Razorpay({
    key_id: key_id,
    key_secret: key_secret
  });

  instance.orders.create({
    amount: 1000,
       currency: "INR",
       receipt: '9876',
       payment_capture: true
  }, (error, response) => {

    if ((error)) {
      // handle error
      console.log("error - ", error);
      res.send("err");
    } else {
      // handle success
      console.log("response - ", response);

      res.send("ok");
    }
  });


always getting error - { statusCode: undefined, error: undefined }

can any one help me ?

error from checkout.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.