Advertisement
ginsul

Untitled

Nov 25th, 2018
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //1.client method to retrieve payment ID
  2. const makePayment = this.cfns.httpsCallable('payPalPay');
  3. const paymentIdResult = makePayment({price: 9});
  4.  
  5. paymentIdResult.subscribe(val => {
  6.   //val is empty regardless of what I do on the server-side
  7.   return val.paymentId;
  8. });
  9.  
  10.  
  11.  
  12. //2. server endpoint being called
  13. exports.payPalPay = functions.https.onCall((data, context) => {
  14.   return pay(data, context)
  15. });
  16.  
  17.  
  18.  
  19. //3. actual server-side logic
  20. export function pay(data, context): Observable<string> {
  21.     var subject = new Subject();
  22.   const payReq = ...
  23.  
  24.   paypal.payment.create(payReq, (error, payment) => {
  25.       if (payment.state === 'created') {
  26.         subject.next({paymentId: payment.id});
  27.         subject.complete();
  28.     }
  29.   });
  30.     return subject;
  31.  
  32. //   tried returning string instead of Observable<string>. No luck
  33. //    subject.subscribe(val =>{
  34. //      return val;
  35. //    });
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement