Trying to integrate the «nativescript-stripe»
plugin into my Nativescript Vue
app has been a challenge. The documentation and demos on the plugin's GitHub are geared towards Angular and TypeScript
, making it difficult to adapt for Vue. Can anyone provide guidance on how to properly use the StandardComponent
with Vue and provide insights on the parameters required by
StripeService.createPaymentSession()
?
I attempted to set <Page ref=«cartPage»>
in the template and initialize paymentSession in the mounted()
method:
// Import statements
var paymentSession = {};
export default {
mounted() {
// Not sure if this is the correct approach
paymentSession = StripeService.createPaymentSession(
this.$refs.cartPage,
this.stripeItem.price,
new Listener(this)
);
},
Although my stripe.service.ts
mirrors the Angular demo code, I have configured the publishableKey and backendBaseURL, and have a separate class for Listener:
// Listener class
export class Listener {
public component;
constructor(component) {
this.component = component;
}
onCommunicatingStateChanged(_isCommunicating) {
this.component.changeDetectionRef.detectChanges();
}
// Code from Angular demo
Despite contemplating moving the Listener class to a separate file, that doesn't seem to be the issue currently.
Encountering the error message when running the app:
CONSOLE ERROR file:///node_modules/nativescript-vue/dist/index.js:2129:21 [Vue warn]: Error in mounted hook: "TypeError: _shared_stripe_stripe_service__WEBPACK_IMPORTED_MODULE_6__["StripeService"].createPaymentSession is not a function. (In '_shared_stripe_stripe_service__WEBPACK_IMPORTED_MODULE_6__["StripeService"].createPaymentSession(this.$refs.cartPage, this.stripeItem.price, new _shared_stripe_stripe_service__WEBPACK_IMPORTED_MODULE_6__"Listener")', '_shared_stripe_stripe_service__WEBPACK_IMPORTED_MODULE_6__["StripeService"].createPaymentSession' is undefined)"
UPDATE:
After some adjustments, I managed to get the app up and running with the following setup:
ShoppingCart.vue:
// Vue component code here
stripe.service.ts:
// Stripe service code here
However, I am currently facing an issue where nothing happens when tapping "Payment type". Despite debugging and verifying that the code is executing without errors, the action does not trigger as expected. Specifically, the method presentPaymentMethods()
from the plugin seems to be running without any visible effect.
Any insights or suggestions on this would be greatly appreciated!