Search code examples
paypalpaypal-sandbox

Error on capture sandbox Paypal smart buttons COMPLIANCE_VIOLATION


I'm trying to integrate a very basic Paypal smart button on client side, exactly as on docs page, here is my snippet:

<div id="smart-button-container">
    <div style="text-align: center;">
        <div id="paypal-button-container"></div>
    </div>
</div>
<script src="https://www.paypal.com/sdk/js?client-id=[my_sandbox_app_id]&currency=USD" data-sdk-integration-source="button-factory"></script>
<script>
    function initPayPalButton() {
        paypal.Buttons({
            style: {
                shape: 'rect',
                color: 'gold',
                layout: 'vertical',
                label: 'paypal',
            },
            createOrder: function (data, actions) {
                return actions.order.create({
                    purchase_units: [{ "description": "first product", "amount": { "currency_code": "USD", "value": 5 } }]
                });
            },
            onApprove: function (data, actions) {
                return actions.order.capture().then(function (details) {
                    alert('Transaction completed by ' + details.payer.name.given_name + '!');
                });
            },
            onError: function (err) {
                console.log(err);
            }
        }).render('#paypal-button-container');
    }
    initPayPalButton();
</script>

But I get these errors 422 500 instead of approve:

enter image description here

By checking Networks tab I find these details about error 422:

enter image description here

How to come over this errors ?

{
    "name": "UNPROCESSABLE_ENTITY",
    "details": [
        {
            "issue": "COMPLIANCE_VIOLATION",
            "description": "Transaction cannot be processed due to a possible compliance violation. To get more information about the transaction, call Customer Support."
        }
    ],
    "message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
    "debug_id": "19961f1d1be55",
    "links": [
        {
            "href": "https://developer.paypal.com/docs/api/orders/v2/#error-COMPLIANCE_VIOLATION",
            "rel": "information_link",
            "method": "GET"
        }
    ]
}

Solution

  • For Sandbox testing, create a Sandbox account and associated REST App for a different country -- for example US.