skip to Main Content

I’m new to paypal and sandbox, however the algorithm works fine with my on the localhost,
whereas it fails to complete the transaction on remote, I’m using php laravel

the algorithm on my paypal controller :

 $request = new OrdersCreateRequest();
    $request->prefer('return=representation');
    $request->body = [
         "intent" => "CAPTURE",
         "purchase_units" => [[
             "reference_id" => rand(000000,999999),
             "amount" => [
                 "value" => number_format($amount, 2, '.', ''),
                 "currency_code" => AppModelsCurrency::findOrFail(get_setting('system_default_currency'))->code
             ]
         ]],
         "application_context" => [
              "cancel_url" => url('paypal/payment/cancel'),
              "return_url" => url('paypal/payment/done')
         ]
     ];

    try {
        //ddd($request);
        // Call API with your client and get a response for your call
        $response = $client->execute($request);
       // ddd($response);
   

        // If call returns body in response, you can get the deserialized version from the result attribute of the response
        return Redirect::to($response->result->links[1]->href);

    }catch (HttpException $ex) {

    }

When I dump the response it’s as :

PayPalHttpHttpResponse {#2005 ▼
+statusCode: 201
 +result: {#2012 ▼
 +"id": "29F719283B401012X"
 +"intent": "CAPTURE"
 +"status": "CREATED"
 +"purchase_units": array:1 [▼
  0 => {#1944 ▼
    +"reference_id": "481922"
    +"amount": {#1948 ▼
      +"currency_code": "USD"
      +"value": "150.00"
    }
    +"payee": {#1975 ▼
      +"email_address": "[email protected]"
      +"merchant_id": "MUJ4QB7EWSWDJ"
    }
  }
]
+"create_time": "2022-08-30T10:04:38Z"
+"links": array:4 [▼
  0 => {#1949 ▼
    +"href": "https://api.sandbox.paypal.com/v2/checkout/orders/29F719283B401012X"
    +"rel": "self"
    +"method": "GET"
  }
  1 => {#2017 ▼
    +"href": "https://www.sandbox.paypal.com/checkoutnow?token=29F719283B401012X"
    +"rel": "approve"
    +"method": "GET"
  }
  2 => {#2010 ▼
    +"href": "https://api.sandbox.paypal.com/v2/checkout/orders/29F719283B401012X"
    +"rel": "update"
    +"method": "PATCH"
  }
  3 => {#2009 ▼
    +"href": "https://api.sandbox.paypal.com/v2/checkout/orders/29F719283B401012X   /capture"
    +"rel": "capture"
    +"method": "POST"
    }
  ]
 }

}

and The Exception i get :

PayPalHttpHttpException
{"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":"a548bb80c1863","links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-COMPLIANCE_VIOLATION","rel":"information_link","method":"GET"}]}

I’ve tried multiple ways to resolve it like :
1- Changing the sandbox account region from EGY to US.
2- Changing the entire paypal account.

I would appreciate a little assistance here.
Thanks in advance.

2

Answers


  1. Chosen as BEST ANSWER

    After a long debugging, the thing turn out to be after the payments. nothing wrong with paypal. I debugged untill I found the payment status "completed" After the payment, I update my DB records. in laravel I used findOrFail($id) method which turns out to be the problem It fails to find the record, I don't know why however this terminates the logic.

    thank you guys.


  2. COMPLIANCE_VIOLATION

    For sandbox testing: the receiving business account should not be from one of the countries listed here. So, it should work if you try again with e.g. a US receiver account (payer/sending account does not matter)

    In the live environment: this answer has more details on the set up needed to receive payments in one of those countries with auto withdrawal to a card or bank.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search