Im trying to add PayPal payments to my site. Im using official @paypal/paypal-js npm package and Nuxt 2.16.
What I expected: Im creating an order at my db on my backend, then creating paypal order and rendering paypal buttons on client side.I expect to continue processing our clients order when paypal hits our webhook on client site with event_type: "PAYMENT.CAPTURE.COMPLETED"
Issue: When I was using sandbox_business and sandbox_personal accounts everything worked just fine.But when I switched to production credentials its not working. Now onError callback is triggering. Funds are withdrawn from the user, and returned after a few seconds.
Here is an Error at paypal dashboard (Error screenshot):
status: 422
issue: COMPLIANCE_VIOLATION
description: The requested action could not be performed semantically incorrect or failed business validation
Here is my client code:
<template><div><div id="paypal-button-container"></div></div></template><script>import { loadScript } from '@paypal/paypal-js';export default { methods: { async createOrder() { await this.$axios.$post("/api/pay", order).then(async (result) =>{ if (result.error) { //some error hadling } else { const paypal = await loadScript({'client-id': "MY_CLIENT_ID", currency: "EUR", intent: "capture", }); await paypal.Buttons({ createOrder: function(data, actions) { return actions.order.create({ purchase_units: [{ amount: { currency_code: 'EUR', value: result.price, }, description: result.order_description, reference_id: result.order_id, }], intent: 'CAPTURE' }); }, onApprove: (data, actions) => { return actions.order.capture().then((orderData, action) => { this.$router.push("/payment/success"); }) }, onError: (err) => { console.log(err); }, }).render('#paypal-button-container'); } } }, },
I tried to pass different values to createOrder function. But couldnt figure out what was the problem.
Also i logged out err from onError callback, but it returned just empty object {}.