<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Swapnil Nakhate on Medium]]></title>
        <description><![CDATA[Stories by Swapnil Nakhate on Medium]]></description>
        <link>https://medium.com/@swapnilnakhate?source=rss-8922af6dea86------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*h4Ys-fP7d0UK-jlp.</url>
            <title>Stories by Swapnil Nakhate on Medium</title>
            <link>https://medium.com/@swapnilnakhate?source=rss-8922af6dea86------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 11:41:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@swapnilnakhate/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[PayUMoney — Payment Gateway Integration with NodeJS and Angular 2/4/6]]></title>
            <link>https://medium.com/@swapnilnakhate/payumoney-payment-gateway-integration-with-nodejs-f715e5fc25a?source=rss-8922af6dea86------2</link>
            <guid isPermaLink="false">https://medium.com/p/f715e5fc25a</guid>
            <category><![CDATA[angular2]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[payumoney]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[payment-gateway]]></category>
            <dc:creator><![CDATA[Swapnil Nakhate]]></dc:creator>
            <pubDate>Tue, 10 Jul 2018 07:10:30 GMT</pubDate>
            <atom:updated>2020-02-05T17:13:21.286Z</atom:updated>
            <content:encoded><![CDATA[<p>You have reached this blog means you are looking for a Payment gateway integration with your site. PayUMoney is one of the best online payment gateway providers in India. To start with integration first you need to create a merchant account on PayUMoney. Once your account is verified by PayUMoney, you can start accepting payments directly to your bank accounts.</p><p>Till now PayUMoney does not have any integration kit available for JavaScript. So I decided to create my own npm package <strong>payumoney_nodejs</strong>. You can easily integrate PayUMoney at server side in NodeJs.</p><p>Here’s link for npm package : <a href="https://www.npmjs.com/package/payumoney_nodejs"><em>https://www.npmjs.com/package/payumoney_nodejs</em></a></p><h3>Steps to use :</h3><p>Install the package with</p><pre>npm install payumoney_nodejs <em>--save</em></pre><p><strong>Set Merchant Key and Salt Key :</strong></p><p>You can get Merchant and Salt key on your PayUMoney dashboard. Also you need to set Authorization header. Set both keys for production and sandbox use.</p><pre>var payUMoney = require(&#39;payumoney_nodejs&#39;);<br>  payumoney.setProdKeys(MERCHANT_KEY, MERCHANT_SALT, PAYUMONEY_AUTHORIZATION_HEADER);<br>  payumoney.setSandboxKeys(MERCHANT_KEY, MERCHANT_SALT, PAYUMONEY_AUTHORIZATION_HEADER);</pre><p><strong>Set Production / Sandbox Mode :</strong></p><p>You can switch between payment modes by setting prod mode to true or false. If you want to use sandbox mode set prod mode to false.</p><pre>payUMoney.isProdMode(true); //set false for use of sandbox mode</pre><p>Now you are done with configuration.</p><p>You can use any front end language to make payment request. We will see how to do it in Angular 2. You can use any language to make payment request from UI. First you need to create a html form in Angular 2 which will accept payment details from user.</p><p>Here’s an example in Angular 2 and NodeJs</p><h3>PayUMoney — Angular 2</h3><p><strong>payumoney.component.html</strong></p><pre>&lt;div class=&quot;payumoney-inner-wrapper&quot;&gt;<br>  &lt;h1&gt;Please enter your details&lt;/h1&gt;<br>  &lt;form (submit)=&quot;submitPaymentForm()&quot;&gt;<br>    &lt;div  class=&quot;form-group&quot;&gt;<br>      &lt;label&gt;First Name :&lt;/label&gt;<br>      &lt;input name=&quot;firstname&quot; id=&quot;firstname&quot; [(ngModel)]=&quot;payUMoney.firstname&quot;<br>             class=&quot;form-control&quot;/&gt;<br>    &lt;/div&gt;<br>    &lt;div  class=&quot;form-group&quot;&gt;<br>      &lt;label&gt;Last Name :&lt;/label&gt;<br>      &lt;input  name=&quot;lastname&quot; id=&quot;lastname&quot; [(ngModel)]=&quot;payUMoney.lastname&quot;<br>             class=&quot;form-control&quot;/&gt;<br>    &lt;/div&gt;<br>    &lt;div  class=&quot;form-group&quot;&gt;<br>      &lt;label&gt;Email :&lt;/label&gt;<br>      &lt;input  name=&quot;email&quot; id=&quot;email&quot; [(ngModel)]=&quot;payUMoney.email&quot;<br>              class=&quot;form-control&quot;/&gt;<br>    &lt;/div&gt;<br>    &lt;div  class=&quot;form-group&quot;&gt;<br>      &lt;label&gt;Phone :&lt;/label&gt;<br>      &lt;input  name=&quot;phone&quot; type=&quot;number&quot; [(ngModel)]=&quot;payUMoney.phone&quot;<br>              class=&quot;form-control&quot;/&gt;<br>    &lt;/div&gt;<br>    &lt;div  class=&quot;form-group disabled-values&quot;&gt;<br>      &lt;label&gt;Package Info :&lt;/label&gt;<br>      &lt;input  name=&quot;productinfo&quot; [(ngModel)]=&quot;payUMoney.productinfo&quot; disabled<br>              class=&quot;form-control&quot;/&gt;<br>    &lt;/div&gt;<br>    &lt;div  class=&quot;form-group disabled-values&quot;&gt;<br>      &lt;label&gt;Amount :&lt;/label&gt;<br>      &lt;input  name=&quot;amount&quot; id=&quot;amount&quot; [(ngModel)]=&quot;payUMoney.amount&quot; disabled<br>              class=&quot;form-control&quot;/&gt;<br>    &lt;/div&gt;</pre><pre>    &lt;button (click)=&quot;goToDashboard()&quot; class=&quot;btn btn-default&quot;&gt;<br>      Cancel<br>    &lt;/button&gt;<br>    &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;<br>      Proceed to Pay<br>    &lt;/button&gt;<br>  &lt;/form&gt;</pre><p><strong>payumoney.component.ts</strong></p><pre>submitPaymentForm() {<br>  if(this.checkValidations(this.payUMoney)) {<br>    this.payUMoneyService.makePayment(this.payUMoney).subscribe(<br>      PayUMoneyModel =&gt; this.onPaymentSuccess(PayUMoneyModel),<br>      error =&gt; this.onPaymentFailure(error)<br>    );<br>  } else {<br>    let message = new Message();<br>    message.isError = true;<br>    message.error_msg = &quot;Fields missing&quot;;<br>    this.messageService.message(message);<br>  }<br>}</pre><p><strong>payumoney.service.ts</strong></p><pre>makePayment(payUMoney : PayUMoneyModel) {<br>  let url = &#39;payment/payumoney&#39;;<br>  let body = payUMoney;<br>  let headers = new Headers({&#39;Content-Type&#39;: &#39;application/json&#39;});<br>  let options = new RequestOptions({headers: headers});<br>  return this.http.post(url, JSON.stringify(body), options)<br>   .map(this.extractData)<br>   .catch(this.handleError);</pre><pre>}</pre><p>You can use any front-end technology for making payumoney request to backend. We are done with front end code. Let’s see how to handle payment request in backend NodeJS.</p><h3>PayUMoney — Backend NodeJS</h3><p>Create three backend post requests. One will make a request to PayUMoney with your payment details. Other two are for handling payment success and failure events.</p><p>Create a backend service for handling PayUMoney transaction request. Payment request body will look like this</p><pre>var requestBody = {<br>    &quot;firstname&quot; : &quot;&quot;,<br>    &quot;lastname&quot; : &quot;&quot;,<br>    &quot;email&quot; : &quot;&quot;,<br>    &quot;phone&quot; : 9911223344,<br>    &quot;amount&quot; : 100,<br>    &quot;productinfo&quot; : &quot;&quot;,<br>    &quot;txnid&quot; : &quot;&quot;, <em>//this must be a genrated at your side</em><br>    &quot;surl&quot; : &quot;http:localhost:8080/payment/success&quot;,<br>    &quot;furl&quot; : &quot;http:localhost:8080/payment/failure&quot;<br>  };</pre><p>You need to generate transaction id dynamically. You can generate it either in front-end or back-end. Transaction id is a unique id you can also use it to verify your payment status.</p><p><strong>PayUMoneyService.ts</strong></p><pre>payUMoney.pay(requestBody, function(error, response) {<br>    if (error) {<br>      <em>// Some error console.log(response);</em><br>    } else {<br>      <em>// You will get a link in response to redirect to payUMoney</em><br>     callback(null, { &#39;payulink&#39; : response });<br>    }<br>  });</pre><p>This API will return you PayUMoney link which you need to render in UI.</p><p><strong>payumoney.component.ts</strong></p><pre>onPaymentSuccess(data: any) {<br>  window.location.href = data.payulink;<br> <em>//This will redirect you to payumoney payment form</em><br>}</pre><p>Now you are on PayUMoney form, fill all the details and make a payment. Once the payment is done, PayUMoney will make a post request to <strong>“surl”</strong> or <strong>“furl”</strong> you have provided while making payment request.</p><p>Parameters <strong>surl </strong>and <strong>furl </strong>must be backend API’s, after payment success or failure, PayUMoney will send POST request to these URLs with details regarding your payment.</p><p>You can handle db related operations (like update payment status in your database) on these API’s. Once you update payment status in your db. You can render payment Success or Failure page in browser.</p><p><strong>PayUMoneyController.ts</strong></p><pre>successPayment(req: express.Request, res: express.Response, next: any): void {<br>  try {<br>    console.log(&#39;payment success body : &#39;+ JSON.stringify(req.body));<br>    let redirectUrl = &#39;http:localhost:8080/payment/success&#39;;<br>    res.redirect(redirectUrl);<br>  } catch(e) {<br>    next(new CostControllException(e.message,e.stack));<br>  }<br>}</pre><p>Similarly create a method for failure. Now, you are done with end-to-end integration with PayUMoney.</p><p>Happy coding.</p><p>Check out sample repo for integration :</p><p>Back End (NodeJS) : <a href="https://github.com/SwapnilNakhate/PayUMoney-NodeJS.git">https://github.com/SwapnilNakhate10/PayUMoney-NodeJS.git</a></p><p>Front End (Angular 6) : <a href="https://github.com/SwapnilNakhate/PayUMoney-Angular6.git">https://github.com/SwapnilNakhate</a><a href="https://github.com/SwapnilNakhate/PayUMoney-NodeJS.git">10</a><a href="https://github.com/SwapnilNakhate/PayUMoney-Angular6.git">/PayUMoney-Angular6.git</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f715e5fc25a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>