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", "abc#gmail.com",
"777777777", "25", successCallback, failureCallback);
var userids=window.localStorage.getItem('userid');
//alert(userids);
if(userids!= null)
{
this.navCtrl.push(HomePage);
}
}
}
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
};
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;
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.
ShowBillingForm: boolean = true;
PlanId: any;
PlanRes: any = [];
PlanDetail: any = [];
CustomField: boolean = false;
placemntCount: any;
totalPlaceCost: any;
costPerPlace: any;
DiscountAmount: any = 30;
DiscountedAmount: any;
NetAmount: any;
// ************************Paytm Payment Process *********************
RequestedData: any;
responseBilling: any;
EmployerId: any;
timestamp: any;
TransactionFormshow: boolean = false;
RequestDataPay: any;
SubmitBillingDetail() {
this.EmployerId = this.userdetail.id;
this.timestamp = +new Date;
this.timestamp.toString();
this.PlanDetailForm.controls['BillingState'].value
this.RequestedData = {
"name": this.PlanDetailForm.controls.BillingName.value,
"email": this.PlanDetailForm.controls.Billingemail.value,
"contactnum": this.PlanDetailForm.controls.Billingcontactnum.value,
"address": this.PlanDetailForm.controls.Billingaddress.value,
"state": this.PlanDetailForm.controls.BillingState.value,
"district": this.PlanDetailForm.controls.BillingDistrict.value,
"employerid": this.EmployerId,
"cmpid": this.userdetail.companyID,
"createdby": this.EmployerId,
// "order_id": Math.random().toString(36).substr(2, 9),
"order_id": Math.floor(10000000000 + Math.random() * 90000000000),
"transaction_id": '',
"status": 'Pending',
"validfrom":this.PlanDetail.valiD_FROM? moment(this.PlanDetail.valiD_FROM).format('YYYY-MM-DD'):parseInt('null'),
"validto":this.PlanDetail.valiD_TO? moment(this.PlanDetail.valiD_TO).format('YYYY-MM-DD'):parseInt('null'),
"Response_msg": 'Successfull',
"TXN_AMOUNT": this.PlanDetailForm.controls.Amount.value,
"Payment_For": 'REGISTRATION',
"CALLBACK_URL": environment.apiUrl + "Payment/PaymentConfirmation",
};
this.spinnerService.show();
this.authenticationService.SaveBillingDetailforRegistration(this.RequestedData).subscribe(res => {
this.responseBilling = res;
this.PurchaseStatus = this.responseBilling.purchasePlanStatus;
this.TransactionFormshow = true;
this.spinnerService.show();
localStorage.setItem('PurchaseStatus', this.PurchaseStatus);
this.RequestDataPay = {
"MID": this.responseBilling.mid,
"WEBSITE": this.responseBilling.website,
"INDUSTRY_TYPE_ID": this.responseBilling.industrY_TYPE_ID,
"CHANNEL_ID": this.responseBilling.channeL_ID,
"ORDER_ID": this.responseBilling.ordeR_ID,
"CUST_ID": this.responseBilling.cusT_ID,
"MOBILE_NO": this.responseBilling.mobilE_NO,
"EMAIL": this.responseBilling.email,
"TXN_AMOUNT": this.responseBilling.txN_AMOUNT,
"CHECKSUMHASH": this.responseBilling.checksum,
"CALLBACK_URL": this.responseBilling.callbacK_URL
};
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';
my_form.action = this.responseBilling.paytmgatway;
const myParams = Object.keys(this.RequestDataPay);
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.RequestDataPay[key];
my_form.appendChild(my_tb);
};
document.body.appendChild(my_form);
my_form.submit();
}
As I got some info from http://paywithpaytm.com/developer/discussion/topic/how-to-integrate-paytm-in-angularjs-web-app/, it's clearly written that, paytm doesn’t support for angular js , they only help you in integration and checksum generationlogic and without downloading our SDK it is not possible.
Check https://github.com/Paytm-Payments/Paytm_App_Checksum_Kit_PHP
Related
So i have following JSON:
.json
"type": [ {
"id": 2,
"secondid": "1",
"name": "f",
"positionX": 0,
"positionY": 0
}]
and following Service:
public updateposition(Model: typemodel): Observable<any> {
return this.http.post(this.apiEndPoint + '/type' + '/' + typemodel.id , typemodel);
}
and following TS:
.ts
x: number;
y: number;
updateposition()
{
}
So the goal is to update the json object "type" by clicking a button with html. The html part is no problem. But i don't know how to update the json object with the two new positions x and y which are declared in ts. I want to have the process in the function updateposition(). Do you have any suggestions :) ?
You would have to use Dependency Injection to obtain a reference to the Service in your component and use it to retrieve and store the JSON object. Then update it like you would any other object in JS when the button is clicked, and make the API call. Be sure to subscribe to the result or the API call will not go through.
// ...
export class MyComponent {
public jsonObject: TypeModel = { ... };
public constructor(private service: Service) { }
// ...
public function updateposition() {
this.jsonObject[0].positionX = 52;
this.jsonObject[0].positionY = 42;
this.jsonObject = this.service.updateposition(this.jsonObject).subscribe(
result => {
console.log("The API call returned", result);
}
);
}
}
I want to submit an album gallery with eventTitle and multiple images. I am able to upload multiple images with eventTitle. It might be silly ask but I am new in angular and this is my first project on this. Stuck with this problem. Any reference/document would a big help.
While submitting the form, I just need to pass array of ids of images and eventTitle. My json looks like below:
{
"eventTitle": "Event to be celebrate - Happy New Year..!!",
"image": [
{
"id": 1
},
{
"id": 2
},
{
"id": 3
}
]
}
Problem is here that I am not able to push the array of ids. Only last uploaded image's id is getting push. notable to loop the ids and push into formArray. Can someone please help me how can loop the ids of all uploaded images?
// my Gallery component ts file:
constructor(private fb: FormBuilder,
private http: HttpClient,
private gallaryService: GallaryService,
private fileService: FileService,
private renderer: Renderer2) {
this.gallaryForm = this.fb.group({
eventTitle: [''],
image: this.fb.array([])
});
this.addGallaryImages();
}
ngOnInit() {
}
initSocialProfiles() {
return this.fb.group({
id: ['']
});
}
addGallaryImages() {
const control = this.gallaryForm.controls.image as FormArray; // how to loop it ids of array
const addrCtrl = this.initSocialProfiles();
control.push(addrCtrl);
console.log(addrCtrl);
}
gallaryFormSubmit() { //submitting the form
if (this.gallaryForm.valid) {
const gallaryFormData = this.gallaryForm.value;
gallaryFormData.image = [];
gallaryFormData.image[0] = {};
gallaryFormData.image[0].id = this.imageId;
this.gallaryService.saveGallaryForm(gallaryFormData).subscribe((response) => {
console.log(response);
// this.dialog.closeAll();
alert('New Gallary has been added...!');
});
}
}
onSelectedFile(event){
if (event.target.files.length > 0){
const image = event.target.files[0];
const formData = new FormData();
formData.append('file', image);
this.fileService.saveFile(formData).subscribe(
res => {
console.log(res);
if (res){
this.uploadError = '';
this.imageId = res.id;
const li: HTMLLIElement = this.renderer.createElement('li');
const img: HTMLImageElement = this.renderer.createElement('img');
img.src = res.path;
this.renderer.addClass(img, 'image');
const a: HTMLAnchorElement = this.renderer.createElement('a');
a.innerText = 'Remove';
this.renderer.addClass(a, 'delete-btn');
// a.addEventListener('click', this.deleteProductImage.bind(this, res.response.filename, a));
this.renderer.appendChild(this.image.nativeElement, li);
this.renderer.appendChild(li, img);
this.renderer.appendChild(li, a);
}
else {
this.uploadError = res.massage;
}
},
err => this.error = err
);
}
}
Gallery Service:
saveGallaryForm(gallary){
return this.http.post<any>('http://localhost:8080/gallary/save', gallary)
.pipe(
retry(1),
catchError(this.errorHandl)
);
}
[![ In below console log, last uploaded image id is getting push. I need all uploaded image ids in this array.][1]][1]
I'm new to Vue. I want to read employeeId from a login form and ust it to load some json files named according as employeeId.json like (10000001.json, 20000001.json) and set the json object as a global variable so I can easily access it in all components.
Firstly, I don't know how to dynamically load json files. Using import sees not work. Some one suggested using require should work. But there are not many examples, I don't know where to put require...
Secondly, how do I set the json as global after the employeeId props in? I'm very confused where to put it (inside the export default or not? inside methods or not? or inside created/mounted or not?) and where to use this or not...
This is the script section of my headerNav.vue file.
<script>
//**I placed them here now, it works, but employeeId is hard coded...
import json10000001 from "./json/10000001.json";
import json20000001 from "./json/20000001.json";
import json30000001 from "./json/30000001.json";
// var employeeId = employeeIdFromLogin;
var jsonForGlobal;
var employeeId = 10000001;
var jsonFileCurrentObj;
if (employeeId == "10000001") {
jsonForGlobal = jsonFileCurrentObj = json10000001;
} else if (employeeId == "20000001") {
jsonForGlobal = jsonFileCurrentObj = json20000001;
} else if (employeeId == "30000001") {
jsonForGlobal = jsonFileCurrentObj = json30000001;
}
export default {
// props:{
// employeeIdFromLogin: String,
// },
props:['employeeIdFromLogin'],
jsonForGlobal,
// employeeIdFromLogin,
data() {
return {
docked: false,
open: false,
position: "left",
userinfo: {},
jsonFileCurrent: jsonFileCurrentObj,
// employeeIdFromLogin: this.GLOBAL3.employeeIdFromLogin
// jsonFile: currentJsonFile
};
},
mounted() {
//**I tried put it here, not working well...
// var employeeId = this.employeeIdFromLogin;
// // var jsonForGlobal;
// console.log("headernav.employeeIdFromLogin="+this.employeeIdFromLogin);
// // var employeeId = 10000001;
// var jsonFileCurrentObj;
// if (employeeId == "10000001") {
// this.jsonForGlobal = this.jsonFileCurrentObj = json10000001;
// } else if (employeeId == "20000001") {
// this.jsonForGlobal = this.jsonFileCurrentObj = json20000001;
// } else if (employeeId == "30000001") {
// this.jsonForGlobal = this.jsonFileCurrentObj = json30000001;
// }
},
methods: {
switchPage(pageName) {
this.$emit("switchPage", pageName);
}
//**I don't know how to use the require...
// var employeeId = 10000001;
// getJsonFile(employeeId) {
// this.currentJsonFile = require("../assets/json/" + employeeId + ".json");
// }
}
};
You might want to use vuex to manage global store. But if you don't want includes Vuex, there is a simpler way to have global state:
Define globalStore.js
// globalStore.js
export const globalStore = new Vue({
data: {
jsonForGlobal: null
}
})
then import it and use in component:
import {globalStore} from './globalStore.js'
export default {
props: ['employeeIdFromLogin'],
data: function ()
return {
jsonLocal: globalStore.jsonForGlobal,
jsonFileCurrent: null
}
},
watch: {
employeeIdFromLogin: {
handler(newVal, oldVal) {
const data = require('./json/' + this.employeeIdFromLogin + '.json')
this.jsonFileCurrent = data
globalStore.jsonForGlobal = data
}
}
}
}
I currently have a service that gets an array of json objects from a json file which displays a list of leads. Each lead has an id and when a lead within this list is clicked it takes the user to a view that has this id in the url ie ( /lead/156af71250a941ccbdd65f73e5af2e67 )
I've been trying to get this object by id through my leads service but just cant get it working. Where am I going wrong?
Also, i'm using two way binding in my html.
SERVICE
leads;
constructor(private http: HttpClient) { }
getAllLeads() {
return this.http.get('../../assets/leads.json').map((response) => response);
}
getLead(id: any) {
const leads = this.getAllLeads();
const lead = this.leads.find(order => order.id === id);
return lead;
}
COMPONENT
lead = {};
constructor(
private leadService: LeadService,
private route: ActivatedRoute) {
const id = this.route.snapshot.paramMap.get('id');
if (id) { this.leadService.getLead(id).take(1).subscribe(lead => this.lead = lead); }
}
JSON
[
{
"LeadId": "156af71250a941ccbdd65f73e5af2e66",
"LeadTime": "2016-03-04T10:53:05+00:00",
"SourceUserName": "Fred Dibnah",
"LeadNumber": "1603041053",
},
{
"LeadId": "156af71250a999ccbdd65f73e5af2e67",
"LeadTime": "2016-03-04T10:53:05+00:00",
"SourceUserName": "Harry Dibnah",
"LeadNumber": "1603021053",
},
{
"LeadId": "156af71250a999ccbdd65f73e5af2e68",
"LeadTime": "2016-03-04T10:53:05+00:00",
"SourceUserName": "John Doe",
"LeadNumber": "1603021053",
}
]
You didn't used the newly created leads array (const leads is not this.leads), so do this:
getLead(id: any) {
return this.getAllLeads().find(order => order.LeadId === id);
}
And change your map to flatMap, because from the server you get an array, but you have to transform it to a stream of its items:
getAllLeads() {
return this.http.get('../../assets/leads.json').flatMap(data => data);
}
Don't forget to import it if you have to: import 'rxjs/add/operator/flatMap';
You can have getLead in your component level itself since you are not making any api to get the information. In your component,
this.lead = this.leads.find(order => order.id === id);
or to make the above service work, just do leads instead of this.leads
const lead = leads.find(order => order.id === id);
Based on How can I use/create dynamic template to compile dynamic Component with Angular 2.0 I'm currently facing a timing problem when it comes to dynamic property creation of a component model from a json string that is retrieved from a remote server.
Properties are dynamically created properly within in a new entity - that is later assigned to the empty entity, but the hosting component has been already bound to the empty entity and does not know anything about the dynamically created properties at initialization time. It seems that the creation of the hosting component is already finished when the json result from server arrives asynchronously and a bit later.
As a result a list of empty components without any property data is applied to the page. The number of displayed components is equal to the dynamically added properties. But the dynamic data binding obviously does not know anything about the data attached to the properties.
The forementioned original approach loops through a set of hard wired properties of an entity object to assemble the complete template for each property using the specific propertyname.
Defining a hard wired entity object:
entity = {
code: "ABC123",
description: "A description of this Entity"
};
Assembling a dynamic template string looping through properties of entity:
import {Injectable} from "#angular/core";
#Injectable()
export class DynamicTemplateBuilder {
public prepareTemplate(entity: any, useTextarea: boolean){
let properties = Object.keys(entity);
let template = "<form >";
let editorName = useTextarea
? "text-editor"
: "string-editor";
properties.forEach((propertyName) =>{
template += `
<${editorName}
[propertyName]="'${propertyName}'"
[entity]="entity"
></${editorName}>`;
});
return template + "</form>";
}
}
My approach tries to deal with a full configurable approach:
Json string
{
"code": {
"id": "ADRESSE-UPDATE-001",
"componentType": "text-editor",
"rows": 5,
"cols": 25,
"value": "Hello !"
},
"description": {
"id": "ADRESSE-UPDATE-002",
"componentType": "string-editor",
"rows": 1,
"cols": 50,
"value": "Please enter some data"
},
"Street": {
"id": "ADRESSE-UPDATE-003",
"componentType": "text-editor",
"rows": 10,
"cols": 100,
"value": "Mainstreet"
},
"City": {
"id": "ADRESSE-UPDATE-004",
"componentType": "text-editor",
"rows": 3,
"cols": 5,
"value": "Hamburg"
}
}
Basically the Json retrieval and property creation is organized as:
import { Injectable } from '#angular/core';
import {Http, Response} from "#angular/http";
import { Headers, RequestOptions } from '#angular/http';
import {IValue, IEntityClassAdvanced, Member} from './dynamic-config-interfaces';
var jsonX;
#Injectable()
export class DynamicConfigBuilder{
constructor(private http: Http)
{
}
getEntity(callback):any{
this.callConfigApi(callback);
}
callConfigApi(callback:any) {
jsonX = null;
var content = { "Action": "REQUEST-FOR-CONFIG", "Type": 'CONFIG', "Raw":""};
var jsonText = JSON.stringify(content);
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
this.http.post('http://localhost:9123/tasks/config',jsonText, options)
.map((res: Response) => res.json())
.subscribe((message: string) => {
jsonX = JSON.parse(message);
console.log(JSON.stringify(jsonX));
//alert("loaded from server: " + JSON.stringify(jsonX));
var entity: IEntityClassAdvanced = {};
Object.keys(jsonX).forEach(function (key) {
entity[key] = { propertyValue: null };
var val = entity[key];
val.propertyValue = new Member().deserialize(jsonX[key]);
});
callback(entity);
});
}
}
Necessary Interfaces and types are located in a separate file:
import { Injectable} from '#angular/core';
//--- typed nested object from json:
export interface Serializable<T> {
deserialize(input: Object): T;
}
#Injectable()
export class Member implements Serializable<Member> {
id: string;
componentType: string;
rows: number;
cols:number;
value:string;
deserialize(input) {
this.id = input.id;
this.componentType = input.componentType;
this.rows = input.rows;
this.cols = input.cols;
this.value = input.value;
return this;
}
}
//--- dynamic object builder elements
export interface IValue {
propertyValue: Member
}
export interface IEntityClassAdvanced {
[name: string]: IValue;
}
//--- end dynamic object builder
Within the callback method the late assignment occurs:
private entityCallback(entityItem:any)
{
//alert("--->" + JSON.stringify(entityItem));
this.entity = entityItem;
this.refreshContent();
}
The template creation comes with a slightly different flavour:
public prepareTemplate(entity:any, useTextarea: boolean){
let properties = Object.keys(entity);
let template = "<form >";
let editorName = useTextarea
? "otago-text-editor"
: "string-editor";
properties.forEach((propertyName) =>{
// alert(propertyName);
let targetComponent = entity[propertyName]["propertyValue"]["componentType"];
template += `
<${targetComponent}
[propertyName]="'${propertyName}'"
[entity]="entity"
></${targetComponent}>`;
});
return template + "</form>";
}
When trying a hard wired approach using an nested inline object that already exists at compile time the binding works fine:
var json = {
code: {
id: "ADRESSE-UPDATE-001",
componentType: "text-editor",
rows:5,
cols:25,
value:"Hello !"
},
description: {
id: "ADRESSE-UPDATE-002",
componentType: "string-editor",
rows:1,
cols:50,
value:"Please enter some data"
},
firstMember: {
id: "ADRESSE-UPDATE-003",
componentType: "text-editor",
rows:10,
cols:100,
value:"Mainstreet"
},
secondMember: {
id: "ADRESSE-UPDATE-004",
componentType: "text-editor",
rows:3,
cols:5,
value:"Hamburg"
}
};
Any suggestions concerning this generic component creation approach/timing problem appreciated.