Paypal 错误 ppxo_no_token_passed_to_ payment 又名“没有价值传递到付款”

php*_*_qq 5 javascript rest paypal

我已经在我的应用程序中实现了贝宝快速结帐,一切都运行顺利,直到我今天不得不更改我的凭据。为了进行测试,我使用了自己的 paypal 帐户,但现在必须将其与公司的帐户进行切换,因此我创建了一个 REST 应用程序并交换了调试和生产密钥。突然,当我尝试付款时,我发现ppxo_no_token_passed_to_payment,如果我切换回旧的公钥,它仍然有效。我怀疑这是贝宝的一个问题,我需要授权或启用应用程序或其他东西,但遗憾的是我不记得了......

这是有问题的代码,但我确实相信它没有任何问题,正如我所说,如果我输入旧的公钥,那么它仍然可以正常工作。

  getPaypalButton(container: any, paypal: any) {

    return paypal.Button.render({

      env: __DEV__ ? "sandbox" : "production",

      style: this.style(),

      // Pass the client ids to use to create your transaction on sandbox and production environments

      client: {
        // from https://developer.paypal.com/developer/applications/
        sandbox: env.payments.paypal.sandbox, 
        production: env.payments.paypal.production
      },

      // Pass the payment details for your transaction
      // See https://developer.paypal.com/docs/api/payments/#payment_create for the expected json parameters
      payment: this.payment.bind(this),

      // Display a "Pay Now" button rather than a "Continue" button
      commit: true,

      // Pass a function to be called when the customer completes the payment
      onAuthorize: this.authorize.bind(this),

      // Pass a function to be called when the customer cancels the payment
      onCancel: this.cancel.bind(this)

    }, container)

  style() {
    return {
      label: 'paypal',
      size: 'responsive',    // small | medium | large | responsive
      shape: 'rect',     // pill | rect
      color: 'blue',     // gold | blue | silver | black
      tagline: false
    };
  }

  payment(data: any, actions: any) {

    return actions.payment.create({
      transactions: [
        {
          amount: {
            total: i18n.currencies.toHumanReadable(this.moneyControl.internalInput.value, "EUR").toFixed(2),
            currency: "EUR"
          }
        }
      ]
    }).catch((error: any) => {
      if (!this.moneyControl.internalInput.value) {
        this.moneyControl.displayError("validation.required");
      } else {
        this.moneyControl.displayError("deposit.paypalerror");
      }
    });
  }

  authorize(data: any, actions: any) {
    return web.request("/paypal", {
      method: "POST",
      data: {
        token: data.paymentToken,
        payment_id: data.paymentID,
        payer_id: data.payerID
      }
    }).then((response: any) => {
      console.log('The payment was completed!', response);

      this.completed();
    }).catch(function (error) {
      console.log(error);
    });
  }

  cancel(data: any) {
    this.moneyControl.displayError("deposit.paypalcancel");
  }
Run Code Online (Sandbox Code Playgroud)

需要注意的一件事是抛出的错误说env: "production",但是__DEV__true

country: "US"
env: "production"
host: "192.168.0.100:8080"
lang: "en"
pageID: ...
path: "/"
prev_corr_ids: ""
referer: "192.168.0.100:8080"
timestamp: 1528128652378
uid: ...
ver: "4.0.199"
windowID: ...
Run Code Online (Sandbox Code Playgroud)

Ade*_*lin 0

文档来看,传递给函数的对象actions.payment.create应该包含一个payment键。

因此,您应该拥有:而不是现在传递的对象:

return actions.payment.create({
  payment: {
    transactions: [
      {
        amount: {
          total: i18n.currencies.toHumanReadable(this.moneyControl.internalInput.value, "EUR").toFixed(2),
          currency: "EUR"
        }
      }
    ]
  }
})
Run Code Online (Sandbox Code Playgroud)