2015-12-03 5 views
0

Я пытаюсь добавить платеж PayPal на свой сайт с помощью cURL, и я нашел, как получить токен доступа, но я не понимаю, как преобразовать этот запрос (предоставленный разработчиком PayPal) в PHP cURL, чтобы перейти к оплате.API PayPal: запрос curl для PHP cURL

curl -v https://api.sandbox.paypal.com/v1/payments/payment \ 
-H 'Content-Type: application/json' \ 
-H 'Authorization: Bearer <Access-Token>' \ 
-d '{ 
    "intent":"sale", 
    "redirect_urls":{ 
    "return_url":"http://example.com/your_redirect_url.html", 
    "cancel_url":"http://example.com/your_cancel_url.html" 
    }, 
    "payer":{ 
    "payment_method":"paypal" 
    }, 
    "transactions":[ 
    { 
     "amount":{ 
     "total":"7.47", 
     "currency":"USD" 
     } 
    } 
    ] 
}' 

ответ

0

Было бы что-то подобное (не проверено):

$ch = curl_init('https://api.sandbox.paypal.com/v1/payments/payment'); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json', 
'Authorization: Bearer <Access-Token>' 
)); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

$payloadData = '{ 
    "intent":"sale", 
    "redirect_urls":{ 
    "return_url":"http://example.com/your_redirect_url.html", 
    "cancel_url":"http://example.com/your_cancel_url.html" 
    }, 
    "payer":{ 
    "payment_method":"paypal" 
    }, 
    "transactions":[ 
    { 
     "amount":{ 
     "total":"7.47", 
     "currency":"USD" 
     } 
    } 
    ] 
}'; 

curl_setopt($ch, CURLOPT_POSTFIELDS, $payloadData); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 

$result = curl_exec($ch); 
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
curl_close($ch); 
+0

бет он получит проблемы с CURLOPT_VERIFYPEER следующим: р – hanshenrik