0

I am attempting to create a PayPal checkout order on my Vue site. I am currently passing two props to the component as well as two data objects

  props: {
    price: Number,
    shipping: Number,
  },
  data() {
    return {quantity: 1, switches: 'red'}
  },

I am referencing these four variables in my code as this.price, this.shipping etc. I have confirmed these are all valid

I am attempting to access these inside a method but this is being over-ridden and all four of these are undefined.

I still don't quite understand this, but I was under the impression that using an arrow function as I have done should stop this from changing. Is this not the case?

Code

   await paypal.Buttons({
      style: {
        layout: 'vertical',
        color: 'black',
        shape: 'pill',
      },
      createOrder: (data, actions) => {
        return actions.order.create({
          purchase_units: [{
            amount: {
              currency_code: "USD",
              value: ((this.price + this.shipping) * this.quantity).toString(),
              breakdown: {
                item_total: {  /* Required when including the `items` array */
                  currency_code: "USD",
                  value: this.price.toString()
                },
                shipping: {
                  currency_code: "USD",
                  value: this.shipping.toString()
                }
              }
            },
            items: [
              {
                name: "First Product Name", /* Shows within upper-right dropdown during payment approval */
                description: "Optional descriptive text..", /* Item details will also be in the completed paypal.com transaction view */
                unit_amount: {
                  currency_code: "USD",
                  value: this.price.toString()
                },
                quantity: this.quantity.toString
              },
            ]
          }]
        });
      },
    }).render('#paypal-button-container')
Nash Anderson
  • 70
  • 1
  • 8
  • 1
    How have you defined the method? If it's an arrow function itself, that's your problem – Phil Sep 22 '21 at 04:25
  • 1
    Does this answer your question? [Use arrow function in vue computed does not work](https://stackoverflow.com/questions/42971081/use-arrow-function-in-vue-computed-does-not-work) – Phil Sep 22 '21 at 04:26

0 Answers0