Ionic with stripe checkout integration(custom)


#1

I have the following code in my ionic 2/3 app which is working fine in terms of getting the token id and showing it in the console.log.

collectCardInfo(){
this.tK = null;

if (this.validate()) {

this.handler.open({
name: ‘XXXXXX’,
description: ‘XXXXXXXXXXX’,
email: xxxx,
amount: xxxxx,
token: function (token: any){
console.log("token.id: " + token.id);
}
})
} // if (valid)
}

However, I seem to be missing something. After getting the token, I need to send it to my server. In my case I use a service like ( this.paymentService.postOrder(){…} ) to post the token.id, order details, and shipping info to my server. However, I can not seem to get the callback function to work. if I do this:

token: function(token:any){
this.paymentService.postOrder(){…}
}

I get an error saying it can’t call property postOrder of undefined. Any other function I try to call in this callback errors out saying the functionName is not a function. Nothing I have tried seems to work. I’m sure the problem is syntax with respect to how I’m trying to call it. But I’m stuck. Any help would be appreciated. Thanks!


#2

Please edit your post, it is not very readable at the moment.
Use the </> button above the input field to format your code, command line output or error message (select the text first, then click the button or wrap it in ``` manually). Check the preview if it looks better. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.


#3

Use ionic-native. If you insist on doing this the hard way, never type the word “function” inside of one. Always use lambdas and arrow functions.


#4

You’ve had good experiences with it? It was in beta the last time I thought about incorporating it, looks to be out of beta now. I guess it’s going on the todo list!


#5

@repropos Being new to ionic I suppose I am making a lot of errors. I tried for several days to use Ionic Native Stripe. I was able to successfully get the token. However, I ran into a problem and maybe you can help.

I could not figure out how to get the validation functions such as validateCardNumber working with the client-side. For instance, the form should be able to check whether the card number is in valid format before sending to Stripe to get a token. In other parts of the form, I am using the validation examples as given by Josh Morony at

https://www.joshmorony.com/advanced-forms-validation-in-ionic-2/

He gives examples on creating a custom validator. I assumed we could use this to include the stripe validators but I was unsuccessful with the format he gave.

Bottom line, can you provide some direction as to how to incorporate the Stripe validators? Do I need to scrap the validation scheme as use an onBlur instead? Any ideas would be helpful as I am stuck.


#6

Can the ionic-native plugin be used for charging credit cards? I don’t see any info on the plugin website about charging - it only shows how to save card info and create a token.