richnologies / ngx-stripe

Angular 6+ wrapper for StripeJS
MIT License
219 stars 77 forks source link

rxjs6 version Invalid value for create(): paymentRequest #33

Closed dottodot closed 5 years ago

dottodot commented 6 years ago

Just given the rxjs6 version a try but the paymentRequestButton doesn't seem to work now

    this.paymentRequest = this.stripeService.paymentRequest({

    });

    this.prButton = this.elements.create('paymentRequestButton', {
      paymentRequest: this.paymentRequest
    });

gives an error of

Uncaught Error: Invalid value for create(): paymentRequest should be a stripe.paymentRequest(...) instance. You specified: [object Object].
SamuelMarks commented 6 years ago

Maybe it's out of context?:

this.prButton = this.elements.create('paymentRequestButton', {
  paymentRequest: this.paymentRequest.bind(this)
});

Or:

const self = this;
this.prButton = this.elements.create('paymentRequestButton', {
  paymentRequest: self.paymentRequest
});
dottodot commented 6 years ago

bind give an error of

this.paymentRequest.bind is not a function

and the self approach just give the same result as originally posted and as I'm already attached it to a component property it's pretty must the same thing.

dottodot commented 6 years ago

Also the current version used with rxjs-compat only has an issue, doesn't throw any errors but doesn't show a button either.

SamuelMarks commented 6 years ago

Hmm, not sure then.

PS: You could always try the branch on my fork: https://github.com/SamuelMarks/ngx-stripe/tree/ng6

dottodot commented 6 years ago

OK took a while and after copying the code I was able to work out how to make it work.

Previously I was able to do the following

this.paymentRequest = this.stripeService.paymentRequest({});
this.prButton = this.elements.create('paymentRequestButton', {
     paymentRequest: this.paymentRequest
});

but now you need to subscribe to this.stripeService.paymentRequest and the pass in the the response i.e

this.stripeService.paymentRequest({}).subscribe(paymentRequest => {
 this.paymentRequest = paymentRequest;
 this.prButton = this.elements.create('paymentRequestButton', {
     paymentRequest: this.paymentRequest
 });
})
SamuelMarks commented 6 years ago

Looks at the Network, many make their own Angular 6 compatible forks: https://github.com/richnologies/ngx-stripe/network

See also, rxjs' official branch: https://github.com/richnologies/ngx-stripe/tree/6.x

dottodot commented 6 years ago

This branch works fine just need the docs updating for paymentRequest as it works slightly different to the previous version as per my comment above

richnologies commented 5 years ago

Thanks, I will update the docs