Paypal error ppxo_no_token_passed_to_payment aka "No value passed to payment"

时间:2018-06-04 17:11:36

标签: javascript rest paypal

I have implemented paypal express checkout in my app and everything was running smooth until I had to change my credentials today. For testing I used my own paypal account but now it has to be switched with the company's one, so I created a REST app and swapped the debug and production keys. Suddenly when I try to pay I get ppxo_no_token_passed_to_payment, if I switch back to my old public key its still working. I suspect this is an issue over at paypal where I need to authorize or enable the app or something but sadly I can not remember...

Here is the code in question, but I do believe there is nothing wrong with it, as I said, if I put my old public key then it's still working fine.

  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");
  }

One thing to notice is that the thrown error says env: "production", however __DEV__ is 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: ...

1 个答案:

答案 0 :(得分:0)

the docs开始,传递给actions.payment.create函数的对象应包含payment密钥。

因此,您应该拥有:

,而不是您现在传递的对象
return actions.payment.create({
  payment: {
    transactions: [
      {
        amount: {
          total: i18n.currencies.toHumanReadable(this.moneyControl.internalInput.value, "EUR").toFixed(2),
          currency: "EUR"
        }
      }
    ]
  }
})