无法从 LWC 创建 Stripe 付款方式

问题描述 投票:0回答:1

错误是stripe.createPaymentMethod在lwc中不起作用?该方法 renderCallback 从 salesforce 中的静态资源加载 Stripe js。

async renderedCallback() {
  if (this.stripeJsLoaded) {
    return;
  }

  this.stripeJsLoaded = true;

  await Promise.all([loadScript(this, StripeJS)]);
  this.stripe = Stripe("pk......");

  this.stripeElements = this.stripe.elements();

  var style = {
    base: {
      color: "#32325d",
      fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
      fontSmoothing: "antialiased",
      fontSize: "16px",
      "::placeholder": {
        color: "#aab7c4"
      }
    },
    invalid: {
      color: "#fa755a",
      iconColor: "#fa755a"
    }
  };

  const cardElementContainer = this.template.querySelector('.card-element');
  if (cardElementContainer) {
    this.cardElement = this.stripeElements.create('card', { style: style, hidePostalCode: true });
    this.cardElement.mount(cardElementContainer);
  } else {
    console.error('Element with class "card-element" not found in the template.');
  }
}

此方法是在stripe上创建付款方式,但不起作用。预期结果应该是付款方式 ID。

async tsCreateCardOnStripe() {
  if (this.isStripeCardFound) {
    this.stripeDataCardId = this.paymentMethod.Stripe_Id__c;
    if (this.oneTimePay || this.defaultPay) {
      this.tsCreatePaymentOnStripe();
    } else if (this.subscriptionPay) {
      this.tsCreateProductsOnStripe();
    }
  } else {
    const billingDetails = {
      name: 'Jenny Rosen',
    };

    const payload = await this.stripe.createPaymentMethod({
      type: "card",
      card: this.stripeElements.getElement('card'),
      billing_details: billingDetails
    });

    console.log('payload : ' + JSON.stringify(payload));
  }
}

console.log('有效负载:' + JSON.stringify(有效负载));没有日志返回?

stripe-payments salesforce lwc
1个回答
0
投票

你找到解决办法了吗?

© www.soinside.com 2019 - 2024. All rights reserved.