0

As we can check the status that either payment api is supported or not. Using window object:

window.PaymentRequest

Is there any way to check after payment what is status of PaymentResponse using only window object?

I don't have access to the code of payment and I am trying to check status using window object only.

Dharmik Raval
  • 101
  • 10

1 Answers1

0

You can get the response back. See this

// global
const { PaymentRequest } = window;

// Selectors
const buttons = document.querySelectorAll('button');

// config
const paymentMethods = [
  {
    supportedMethods: ['basic-card']
  }
];

const paymentDetails = {
  total: {
    label: 'What you pay',
    amount: {
      currency: 'USD',
      value: 10
    }
  }
};


const paymentRequest = PaymentRequest && new PaymentRequest(
  paymentMethods,
  paymentDetails
);

const addItemToCart = ({target}) => {
  paymentRequest
  .show()
  .then(paymentResponse => {
    return paymentResponse.complete().then(response => {
      console.log(response)
    });
  })
  .catch(reason => console.error(`Error occurred: ${reason}`));
};

buttons.forEach(button => button.addEventListener('click', addItemToCart));

Here's a codepen link

https://codepen.io/elmahdim/pen/yodVzw?editors=1111

Anas M.I
  • 512
  • 2
  • 8