Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i integrate paytm in angular4

I'm integrating paytm in angular 4. paytm plugin is successfully added in project , but i don't know how to import paytm plugin in ts file. and call java file file function.

please help me... here is my code

import { Nav, Platform } from 'ionic-angular';
import { Component, OnInit } from '@angular/core';
import { NavController } from 'ionic-angular';
import {} from 'jasmine';
import {LoginPage} from "../login/login";
import {SignUpPage} from "../signup/signup";
import {HomePage} from "../home/home";
import { Paytm } from '@ionic-paytm/paytm';

@Component({
    selector: 'page-apphome',
    templateUrl: 'apphome.html'
})
export class AppHomePage implements OnInit {

    constructor(public navCtrl: NavController ,public paytm:Paytm) {}

    ngOnInit(){
        window.plugins.paytm.startPayment("526", "25862", "[email protected]", 
           "777777777", "25", successCallback, failureCallback);
        var userids=window.localStorage.getItem('userid');
        //alert(userids);
        if(userids!= null)
        {
            this.navCtrl.push(HomePage);
        }
    }
}
like image 533
webaddicted Avatar asked Aug 01 '17 09:08

webaddicted


3 Answers

You can simply archive it.

Create CHECKSUMHASH using backend (.net, php, etc..) with help of API and that just replace checksumhash in form. or you can create form in component itself when you get checksumhash from API.

Create CHECKSUMHASH with help of paytm documentation. STEP 2. and than return CHECKSUMHASH. Take all parameters from frontend.

For Example : I had used just one button for transaction not needed any form now. after checksumhash i will create form.

app.component.html :

<button type="button" (click)="submitForm()">PAY NOW</button>

app.component.ts :

constructor(private http: HttpClient) { }

// I have all below fields values
paytm = {
    MID: "xxxxx", // paytm provide
    WEBSITE: "WEBSTAGING", // paytm provide
    INDUSTRY_TYPE_ID: "Retail", // paytm provide
    CHANNEL_ID: "WEB", // paytm provide
    ORDER_ID: "xxxxx", // unique id
    CUST_ID: "xxxxx", // customer id
    MOBILE_NO: "xxxx", // customer mobile number
    EMAIL: "xxxx", // customer email
    TXN_AMOUNT: "10.00", // transaction amount
    CALLBACK_URL: "http://localhost:4200/paymentverity", // Call back URL that i want to redirect after payment fail or success
  };

submitForm() {
    // I will do API call and will get CHECKSUMHASH.
    this.http.post('https://myAPI.com/createchecksum', this.paytm)
       .subscribe((res: any) => {
             // As per my backend i will get checksumhash under res.data
             this.paytm['CHECKSUMHASH'] = res.data;
             // than i will create form
             this.createPaytmForm();
        };       
};

createPaytmForm() {
   const my_form: any = document.createElement('form');
    my_form.name = 'paytm_form';
    my_form.method = 'post';
    my_form.action = 'https://securegw-stage.paytm.in/order/process';

    const myParams = Object.keys(this.paytm);
    for (let i = 0; i < myParams.length; i++) {
      const key = myParams[i];
      let my_tb: any = document.createElement('input');
      my_tb.type = 'hidden';
      my_tb.name = key;
      my_tb.value = this.paytm[key];
      my_form.appendChild(my_tb);
    };

    document.body.appendChild(my_form);
    my_form.submit();
// after click will fire you will redirect to paytm payment page.
// after complete or fail transaction you will redirect to your CALLBACK URL
};
like image 197
Shashikant Devani Avatar answered Oct 16 '22 03:10

Shashikant Devani


PayTM and PayU both are still on old web service, they still dont support REST so, you will need to prepare the all the params in your web api and then send it as name value array and then bind it to angular page and then either do autopost or manual post

<form ngNoForm  #myFormPost name="myFormPost" id="payForm" [action]="postURL" method="POST">
    <ng-container *ngFor="let input of apiResponse">
        <input *ngIf="!input.multiline" type="hidden" [name]="input.name" [value]="input.value" />
        <textarea *ngIf="input.multiline" [name]="input.name" class="textarea--hidden">{{input.value}}</textarea>
      </ng-container>
      <button (click)="onPost()">Post</button> 
</form>
{{input.value}} Post {{input.value}} Post
 Dictionary<string, string> dicPam = new Dictionary<string, string>
            {
                { "MID", parameters.MID },
                { "CHANNEL_ID", parameters.CHANNEL_ID },
                { "INDUSTRY_TYPE_ID", parameters.INDUSTRY_TYPE_ID},
                { "WEBSITE", parameters.WEBSITE},
                { "EMAIL", parameters.EMAIL},
                { "MOBILE_NO", "9999999999" },
                { "CUST_ID", parameters.CUST_ID },
                { "ORDER_ID", parameters.ORDER_ID },
                { "TXN_AMOUNT", parameters.TXN_AMOUNT},
                { "CALLBACK_URL", parameters.CALLBACK_URL} //This parameter is not mandatory. Use this to pass the callback url dynamically.
            };

        var payTMParams = _mapper.Map<PayTMParams>(parameters);
        payTMParams.CHECKSUMHASH= CheckSum.generateCheckSum(merchantKey, dicPam);

        var PayParams = new PaymentParams();
        PayParams.PostURL= _configuration.GetSection("PaymentConfig:PayTM:POSTURL").Value;
        foreach (var item in dicPam)
        {
            PayParams.PayParams.Add(new ValPair { Name = item.Key, Value = item.Value });
        }

        PayParams.PayParams.Add(new ValPair { Name = "CHECKSUMHASH", Value = payTMParams.CHECKSUMHASH });
        return PayParams;
like image 32
Vikash Sharma Avatar answered Oct 16 '22 03:10

Vikash Sharma


Regarding paytm,they are not supporting REST.So it is better to follow ordinary Form submitting Mechanism.so as per their documentation,we can pass the required parameters along with CHECKSUMHASH as ordinary POST request.for that in form

<form ngNoForm method="post"action="https://securegwstage.paytm.in/theia/processTransactio">

ngNoForm will directly post all data to their gateway.

like image 23
Sreerag Avatar answered Oct 16 '22 04:10

Sreerag