Guest User

Untitled

a guest
Mar 22nd, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. 1. create a ionic project
  2. * ionic start ionicStripe blank
  3. 2. install the stripe plugin
  4. * ionic cordova plugin add cordova-plugin-stripe
  5. * npm install --save @ionic-native/stripe
  6. 3. add stripe to module.ts import { Stripe } from '@ionic-native/stripe';
  7.  
  8. 4. in payment page :
  9. * import stripe again import { Stripe } from "@ionic-native/stripe"; and add it to constructor
  10.  
  11. 5. get credit card information
  12.  
  13. cardinfo: any = {
  14. number: 4242424242424242,
  15. expMonth: 8,
  16. expYear: 2020,
  17. cvc: 213
  18. }
  19. 6. I need togenerate token with stripe ans to make payment,
  20. in my case, I record all the orders in my database before starting the payment process with stripe
  21.  
  22. * this.stripe.setPublishableKey('pk_test**************');
  23. * this.stripe.createCardToken(this.cardinfo).then((response)=>{
  24. // I get my token here response.id
  25. });
  26.  
  27. 7. i need to save the orders in my database
  28. this.stripe.createCardToken(this.cardinfo).then((response)=>{
  29. // I get my token here response.id
  30. const Payment = skygear.Record.extend('payment');
  31. skygear.publicDB.save(new Payer({
  32. 'token': response,
  33. 'description':"decri[tion payment",
  34. 'prix':100,
  35. })).then((record) => {
  36. console.log(record);
  37. }, (error) => {
  38. console.error(error);
  39. });
  40. });
  41. 8. i create a cloud function
  42.  
  43. const skygear =require ('skygear');
  44. const skygearCloud = require('skygear/cloud');
  45. var stripe = require("stripe")("sk_test********************");
  46. skygearCloud.afterSave('payment', function(record, original, pool, options) {
  47. // write your code
  48. stripe.charges.create({
  49. amount: record.prix,
  50. currency: "usd",
  51. source: record.token.id,
  52. description: record.description
  53. }, function(err, charge) {
  54. if (err) {
  55. console.log("Erreur" + JSON.stringify(err))
  56. }
  57. // asynchronously called
  58. });
  59. }, {
  60. async: false
  61. });
Add Comment
Please, Sign In to add comment