Unsupported Media Type

reeouw
New Community Member

hey guys, Idk what happened but suddenly my paypal express checkout button doesnt work and it says : Unsupported Media Type.

I've copy and paste to make sure that I dont make any typo, but still it doesn't work.

 

and this is my code

 

    var booking = $('.booking'),
    bill = booking.data('bill'),
    afterCheckOutUrl = booking.data('after-checkout-url'),
    orderId = booking.data('order-id');
    paypal.Buttons({
        createOrder: function (data, actions) {
            var el = $('.processing-loader');
            el.show();
            el.find('.text').text('Processing your payment...');
            return actions.order.create({
                purchase_units: [{
                    amount: {
                        "currency_code": "USD",
                        "value": bill
                    }
                }]
            });
        },
        onApprove: function (data, actions) {
            return actions.order.capture().then(function (details) {
                // Call your server to save the transaction
                return fetch(afterCheckOutUrl, {
                    method: 'post',
                    headers: {
                        'content-type': 'application/json',
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    body: JSON.stringify({
                        orderID: orderId
                    })
                })
                .then((res) => res.json())
                .then( function(data){
                  window.location.href = data.redirect;
                })
                .catch( function (err) {
                  alert('payment error '+err)
                });
            });
        },
        onCancel: function (data, actions) {
          var el = $('.processing-loader');
          el.hide();
        }
    }).render('#paypal-button-container');
  }
  paypalPayment();

 

any help? 

Login to Me Too
1 REPLY 1

lbrines
New Community Member

Hi, i have the same problem with this config

paypal.Buttons({
    createOrder: (data, actions) => {
       return actions.order.create({
          'purchase_units': [{
             'amount': {
                'value': costOfPlans[this.plan]
             }
          }]
       })
    },
    onApprove: (data, actions) => {
       return actions.order.capture().then(function (details) {
          alert('Transaction completed: ' + data.orderID);
          return fetch(process.env.API_URL + '/paypal/verifyOrder', {
             method: 'post',
             headers: { 'content-type': 'application/json' },
             body: JSON.stringify({
                orderID: data.orderID
             })
          })
       })
    }
}).render('#paypal-button')

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.