PHP: платеж PayPal прошел успешно, но сумма неверна - PullRequest
2 голосов
/ 08 апреля 2020

Общая информация PayPal PHP Версия SDK / библиотеки: 1.14.0 Среда: и песочница, и язык производства, языковая версия и ОС: PHP 7.2 в Ubuntu 16.10

Я установил сумму в 1 доллар, но после оплаты она всегда стоит 85 долларов («доставка»: «5», «налог»: «10», «промежуточный итог»: «70»), вот коды, я не не знаю, откуда взялась доставка и налоговый сбор.

$product = 'Hello, World!';
$description = 'Hello, World!';
$currency = 'USD';
$price = 1;
$shipping = 0;
$tax = 0;
$paypal = $this->paypal;
$subtotal = $price * 1;
$total = $subtotal + $shipping + $tax;

$payer = new Payer();
$payer->setPaymentMethod( 'paypal' );

$details = new Details();
$details->setShipping( $shipping )
        ->setSubtotal( $subtotal )
        ->setTax( $tax );

$amount = new Amount();
$amount->setCurrency( $currency )
            ->setTotal( $total )
            ->setDetails( $details );

$transaction = new Transaction();
$transaction->setAmount( $amount )
              ->setDescription( $description )
              ->setInvoiceNumber( uniqid() );

$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(  'https://example.org/payment-result'  )
             ->setCancelUrl(  'https://example.org/payment-cancelled'  );

$payment = new Payment();
$payment->setIntent( 'sale' )
        ->setPayer( $payer )
        ->setRedirectUrls( $redirectUrls )
        ->setTransactions( [$transaction] );

$request = clone $payment;

try {
    $payment->create( $apiContext );
} catch (PayPalConnectionException $e) {
   die( $e->getData() );
}

$approvalUrl = $payment->getApprovalLink();
add_header( location: $approvalUrl );

return $payment;

Это журнал:

[03-04-2020 08:55:54] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.sandbox.paypal.com/v1/payments/payment
[03-04-2020 08:55:55] PayPal\Core\PayPalHttpConnection : DEBUG: Request Headers     : POST /v1/payments/payment HTTP/1.1, Host: api.sandbox.paypal.com, Accept: */*, Content-Type: application/json, User-Agent: PayPalSDK/PayPal-PHP-SDK 1.14.0 (platform-ver=7.3.14-1~deb10u1; bit=64; os=Linux_4.10.2-041002-lowlatency; machine=x86_64; crypto-lib-ver=1.1.1d; curl=7.64.0), Authorization: Bearer A21AAFio3Upr9iBH7e-VWazpFCpeYubfFHqbQEbp7QEFfGe354A02bdv3wlBlZOGdXUeSeke5XrRVTrOSPl0xpcFsuqayPzng, Content-Length: 361, , 
[03-04-2020 08:55:55] PayPal\Core\PayPalHttpConnection : DEBUG: Request Data        : {"intent":"sale","payer":{"payment_method":"paypal"},"redirect_urls":{"return_url":"https://example.org/epp/payment-result","cancel_url":"https://example.org/epp/payment-cancelled"},"transactions":[{"amount":{"currency":"USD","total":"1","details":{"shipping":"0","subtotal":"1","tax":"0"}},"description":"Hello world!","invoice_number":"5e86fa1aa46e7"}]}
--------------------------------------------------------------------------------------------------------------------------------

[03-04-2020 08:55:55] PayPal\Core\PayPalHttpConnection : INFO: Response Status  : 201
[03-04-2020 08:55:55] PayPal\Core\PayPalHttpConnection : DEBUG: Response Headers    : Cache-Control: max-age=0, no-cache, no-store, must-revalidate, Content-Language: *, Content-Length: 765, Content-Type: application/json, Date: Fri, 03 Apr 2020 08:55:55 GMT, Paypal-Debug-Id: 3531a093df75a, 
[03-04-2020 08:55:55] PayPal\Core\PayPalHttpConnection : DEBUG: Response Data   : {"id":"PAYID-L2DPUGY3T8910505S347164J","intent":"sale","state":"created","payer":{"payment_method":"paypal"},"transactions":[{"amount":{"total":"1.00","currency":"USD","details":{"subtotal":"1.00","tax":"0.00","shipping":"0.00"}},"description":"Hello world!","invoice_number":"5e86fa1aa46e7","related_resources":[]}],"create_time":"2020-04-03T08:55:54Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAYID-L2DPUGY3T8910505S347164J","rel":"self","method":"GET"},{"href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-44U11063WJ8096549","rel":"approval_url","method":"REDIRECT"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAYID-L2DPUGY3T8910505S347164J/execute","rel":"execute","method":"POST"}]}

================================================================================================================================

[03-04-2020 08:56:36] PayPal\Core\PayPalHttpConnection : INFO: GET https://api.sandbox.paypal.com/v1/payments/payment/PAYID-L2DPUGY3T8910505S347164J
[03-04-2020 08:56:36] PayPal\Core\PayPalHttpConnection : DEBUG: Request Headers     : GET /v1/payments/payment/PAYID-L2DPUGY3T8910505S347164J HTTP/1.1, Host: api.sandbox.paypal.com, Accept: */*, Content-Type: application/json, User-Agent: PayPalSDK/PayPal-PHP-SDK 1.14.0 (platform-ver=7.3.14-1~deb10u1; bit=64; os=Linux_4.10.2-041002-lowlatency; machine=x86_64; crypto-lib-ver=1.1.1d; curl=7.64.0), Authorization: Bearer A21AAFio3Upr9iBH7e-VWazpFCpeYubfFHqbQEbp7QEFfGe354A02bdv3wlBlZOGdXUeSeke5XrRVTrOSPl0xpcFsuqayPzng, , 
[03-04-2020 08:56:36] PayPal\Core\PayPalHttpConnection : DEBUG: No Request Payload
--------------------------------------------------------------------------------------------------------------------------------

[03-04-2020 08:56:36] PayPal\Core\PayPalHttpConnection : INFO: Response Status  : 200
[03-04-2020 08:56:36] PayPal\Core\PayPalHttpConnection : DEBUG: Response Headers    : Cache-Control: max-age=0, no-cache, no-store, must-revalidate, Content-Length: 1585, Content-Type: application/json;charset=UTF-8, Date: Fri, 03 Apr 2020 08:56:36 GMT, Paypal-Debug-Id: 3feac4379943e, 
[03-04-2020 08:56:36] PayPal\Core\PayPalHttpConnection : DEBUG: Response Data   : {"id":"PAYID-L2DPUGY3T8910505S347164J","intent":"sale","state":"created","cart":"44U11063WJ8096549","payer":{"payment_method":"paypal","status":"VERIFIED","payer_info":{"email":"badjohnny.woo-buyer@gmail.com","first_name":"test","last_name":"buyer","payer_id":"FYADYGXGPWBGQ","shipping_address":{"recipient_name":"buyer test","line1":"NO 1 Nan Jin Road","city":"Shanghai","state":"Shanghai","postal_code":"200000","country_code":"C2"},"country_code":"C2"}},"transactions":[{"amount":{"total":"1.00","currency":"USD","details":{"subtotal":"1.00","tax":"0.00","shipping":"0.00"}},"payee":{"merchant_id":"KX6UB59E846NC","email":"badjohnny.woo-facilitator@gmail.com"},"description":"Hello world!","invoice_number":"5e86fa1aa46e7","item_list":{"shipping_address":{"recipient_name":"buyer test","line1":"NO 1 Nan Jin Road","city":"Shanghai","state":"Shanghai","postal_code":"200000","country_code":"C2"}},"related_resources":[]}],"redirect_urls":{"return_url":"https://example.org/epp/payment-result?paymentId=PAYID-L2DPUGY3T8910505S347164J","cancel_url":"https://example.org/epp/payment-cancelled"},"create_time":"2020-04-03T08:55:54Z","update_time":"2020-04-03T08:56:36Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAYID-L2DPUGY3T8910505S347164J","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAYID-L2DPUGY3T8910505S347164J/execute","rel":"execute","method":"POST"},{"href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-44U11063WJ8096549","rel":"approval_url","method":"REDIRECT"}]}

================================================================================================================================

[03-04-2020 08:56:36] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.sandbox.paypal.com/v1/payments/payment/PAYID-L2DPUGY3T8910505S347164J/execute
[03-04-2020 08:56:40] PayPal\Core\PayPalHttpConnection : DEBUG: Request Headers     : POST /v1/payments/payment/PAYID-L2DPUGY3T8910505S347164J/execute HTTP/1.1, Host: api.sandbox.paypal.com, Accept: */*, Content-Type: application/json, User-Agent: PayPalSDK/PayPal-PHP-SDK 1.14.0 (platform-ver=7.3.14-1~deb10u1; bit=64; os=Linux_4.10.2-041002-lowlatency; machine=x86_64; crypto-lib-ver=1.1.1d; curl=7.64.0), Authorization: Bearer A21AAFio3Upr9iBH7e-VWazpFCpeYubfFHqbQEbp7QEFfGe354A02bdv3wlBlZOGdXUeSeke5XrRVTrOSPl0xpcFsuqayPzng, Content-Length: 142, , 
[03-04-2020 08:56:40] PayPal\Core\PayPalHttpConnection : DEBUG: Request Data        : {"payer_id":"FYADYGXGPWBGQ","transactions":[{"amount":{"currency":"USD","total":"85","details":{"shipping":"5","tax":"10","subtotal":"70"}}}]}
--------------------------------------------------------------------------------------------------------------------------------

[03-04-2020 08:56:40] PayPal\Core\PayPalHttpConnection : INFO: Response Status  : 200
[03-04-2020 08:56:40] PayPal\Core\PayPalHttpConnection : DEBUG: Response Headers    : Cache-Control: max-age=0, no-cache, no-store, must-revalidate, Content-Length: 2094, Content-Type: application/json;charset=UTF-8, Date: Fri, 03 Apr 2020 08:56:40 GMT, Paypal-Debug-Id: 6e5ebc5f1a79b, 
[03-04-2020 08:56:40] PayPal\Core\PayPalHttpConnection : DEBUG: Response Data   : {"id":"PAYID-L2DPUGY3T8910505S347164J","intent":"sale","state":"approved","cart":"44U11063WJ8096549","payer":{"payment_method":"paypal","status":"VERIFIED","payer_info":{"email":"badjohnny.woo-buyer@gmail.com","first_name":"test","last_name":"buyer","payer_id":"FYADYGXGPWBGQ","shipping_address":{"recipient_name":"buyer test","line1":"NO 1 Nan Jin Road","city":"Shanghai","state":"Shanghai","postal_code":"200000","country_code":"C2"},"country_code":"C2"}},"transactions":[{"amount":{"total":"85.00","currency":"USD","details":{"subtotal":"70.00","tax":"10.00","shipping":"5.00","insurance":"0.00","handling_fee":"0.00","shipping_discount":"0.00"}},"payee":{"merchant_id":"KX6UB59E846NC","email":"badjohnny.woo-facilitator@gmail.com"},"description":"Hello world!","invoice_number":"5e86fa1aa46e7","item_list":{"shipping_address":{"recipient_name":"buyer test","line1":"NO 1 Nan Jin Road","city":"Shanghai","state":"Shanghai","postal_code":"200000","country_code":"C2"}},"related_resources":[{"sale":{"id":"7LV16321SK655952D","state":"pending","amount":{"total":"85.00","currency":"USD","details":{"subtotal":"70.00","tax":"10.00","shipping":"5.00","insurance":"0.00","handling_fee":"0.00","shipping_discount":"0.00"}},"payment_mode":"INSTANT_TRANSFER","reason_code":"PAYMENT_REVIEW","protection_eligibility":"INELIGIBLE","transaction_fee":{"value":"3.19","currency":"USD"},"parent_payment":"PAYID-L2DPUGY3T8910505S347164J","create_time":"2020-04-03T08:56:39Z","update_time":"2020-04-03T08:56:39Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/sale/7LV16321SK655952D","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/sale/7LV16321SK655952D/refund","rel":"refund","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAYID-L2DPUGY3T8910505S347164J","rel":"parent_payment","method":"GET"}]}}]}],"failed_transactions":[],"create_time":"2020-04-03T08:55:54Z","update_time":"2020-04-03T08:56:39Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAYID-L2DPUGY3T8910505S347164J","rel":"self","method":"GET"}]}

1 Ответ

0 голосов
/ 08 апреля 2020

Вы отправляете ("shipping":"5","tax":"10","subtotal":"70") после того, как покупатель утвердит платеж, когда он вернется на ваш сайт, и вы позвоните в конечную точку PAYID '/ execute', чтобы создать платеж.


Кстати, если вы не продвинулись слишком далеко с этой интеграцией, вы не должны использовать v1 PayPal- PHP -SDK, поскольку он устарел и устарел.

Вместо этого используйте последнюю версию v2 Checkout- PHP -SDK .

...