У меня проблема с интеграцией PayPal PHP Api на моем сайте.Когда я пытаюсь купить что-то с помощью бразильской учетной записи в песочнице, когда захожу на мою страницу paypal_payment_succes.php, я получаю следующую ошибку при выполнении платежа:
{"name":"VALIDATION_ERROR","details":[{"field":"transactions[0].item_list.shipping_address.normalization_status","issue":"Field name is not defined for this resource type."}],"message":"Invalid request. See details.","information_link":"https://developer.paypal.com/docs/api/payments/#errors","debug_id":"e0f0cecbd95f3"}
Кажется, проблема с нормализацией адреса, но я не могу решить ее самостоятельно.Вот создание запроса:
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');
$list = new \PayPal\Api\ItemList();
$item = new \PayPal\Api\Item();
$item->setName("myItem");
$item->setPrice($iten_ht_price);
$item->setCurrency('EUR');
$item->setQuantity(1);
$list->addItem($item);
$details = new \PayPal\Api\Details();
$details->setSubtotal($iten_ht_price);
$details->setTax($item_taxes);
$amount = new \PayPal\Api\Amount();
$amount->setTotal($item_ttc_price);
$amount->setCurrency('EUR');
$amount->setDetails($details);
$transaction = new \PayPal\Api\Transaction();
$transaction->setItemList($list);
$transaction->setDescription($service_info["NAME"]);
$transaction->setAmount($amount);
$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl("https://example.com/paypal_payment_success.php")
->setCancelUrl("https://example.com/paypal_payment_cancel.php");
$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions(array($transaction))
->setRedirectUrls($redirectUrls);
try {
$payment->create($apiContext);
?>
<script type="text/javascript">
window.location.href = '<?php echo $payment->getApprovalLink(); ?>';
</script>
<?php
}
и вот подтверждение платежа:
$payment = \PayPal\Api\Payment::get($_GET['paymentId'], $apiContext);
$execution = new \PayPal\Api\PaymentExecution();
$execution->setPayerId($_GET["PayerID"])
->setTransactions($payment->getTransactions());
try {
$payment->execute($execution, $apiContext);
}
catch (\PayPal\Exception\PayPalConnectionException $ex) {
echo '<div class="alert alert-danger"><strong>'.$l["error_happend"].'</strong></div>';
echo $ex->getData();
error_log("paypal_payment_success.php error: ". $ex->getData());
}
Вот полное содержимое переменной $ payment:
PayPal\Api\Payment::__set_state(array(
'_propMap' =>
array (
'id' => 'PAYID-LR6OIAQ8K6195799T910831S',
'intent' => 'sale',
'state' => 'created',
'cart' => '8GR605689F1809928',
'payer' =>
PayPal\Api\Payer::__set_state(array(
'_propMap' =>
array (
'payment_method' => 'paypal',
'status' => 'VERIFIED',
'payer_info' =>
PayPal\Api\PayerInfo::__set_state(array(
'_propMap' =>
array (
'email' => 'billing-brazil1@example.com',
'first_name' => 'Mg',
'last_name' => 'Doctor',
'payer_id' => 'LQX9UCM6YMM96',
'shipping_address' =>
PayPal\Api\ShippingAddress::__set_state(array(
'_propMap' =>
array (
'recipient_name' => 'Mg Doctor',
'line1' => '1234 Rua Main',
'city' => 'Rio De Janeiro',
'state' => 'RJ',
'postal_code' => '22021-001',
'country_code' => 'BR',
'normalization_status' => 'UNNORMALIZED_USER_PREFERRED',
),
)),
'tax_id_type' => 'BR_CPF',
'tax_id' => '30949017787',
'country_code' => 'BR',
),
)),
),
)),
'transactions' =>
array (
0 =>
PayPal\Api\Transaction::__set_state(array(
'_propMap' =>
array (
'amount' =>
PayPal\Api\Amount::__set_state(array(
'_propMap' =>
array (
'total' => '2.50',
'currency' => 'EUR',
'details' =>
PayPal\Api\Details::__set_state(array(
'_propMap' =>
array (
'subtotal' => '2.00',
'tax' => '0.50',
),
)),
),
)),
'payee' =>
PayPal\Api\Payee::__set_state(array(
'_propMap' =>
array (
'merchant_id' => 'WTK64MCV7B6NC',
'email' => 'billing-facilitator@example.com',
),
)),
'description' => 'SeedBox Starter',
'custom' => '57|6|1|2.50|NEW',
'item_list' =>
PayPal\Api\ItemList::__set_state(array(
'_propMap' =>
array (
'items' =>
array (
0 =>
PayPal\Api\Item::__set_state(array(
'_propMap' =>
array (
'name' => 'SeedBox Starter | Achat | 1 mois',
'price' => '2.00',
'currency' => 'EUR',
'quantity' => 1,
),
)),
),
'shipping_address' =>
PayPal\Api\ShippingAddress::__set_state(array(
'_propMap' =>
array (
'recipient_name' => 'Mg Doctor',
'line1' => '1234 Rua Main',
'city' => 'Rio De Janeiro',
'state' => 'RJ',
'postal_code' => '22021-001',
'country_code' => 'BR',
'normalization_status' => 'UNNORMALIZED_USER_PREFERRED',
),
)),
),
)),
'related_resources' =>
array (
),
),
)),
),
'redirect_urls' =>
PayPal\Api\RedirectUrls::__set_state(array(
'_propMap' =>
array (
'return_url' => 'https://example.com/paypal_payment_success.php?paymentId=PAYID-LR6OIAQ8K6195799T910831S',
'cancel_url' => 'https://example.com/paypal_payment_cancel.php',
),
)),
'create_time' => '2019-03-04T08:38:26Z',
'update_time' => '2019-03-04T08:38:45Z',
'links' =>
array (
0 =>
PayPal\Api\Links::__set_state(array(
'_propMap' =>
array (
'href' => 'https://api.sandbox.paypal.com/v1/payments/payment/PAYID-LR6OIAQ8K6195799T910831S',
'rel' => 'self',
'method' => 'GET',
),
)),
1 =>
PayPal\Api\Links::__set_state(array(
'_propMap' =>
array (
'href' => 'https://api.sandbox.paypal.com/v1/payments/payment/PAYID-LR6OIAQ8K6195799T910831S/execute',
'rel' => 'execute',
'method' => 'POST',
),
)),
2 =>
PayPal\Api\Links::__set_state(array(
'_propMap' =>
array (
'href' => 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-8GR605689F1809928',
'rel' => 'approval_url',
'method' => 'REDIRECT',
),
)),
),
),
))
Заранее спасибо:)