저는 페이팔의 나머지 API를 가지고 놀고 있습니다. 제대로 작동하지 않습니다.PHP PayPal 서버 측 REST API
나는 지불을 위해 제공 한 코드를 복사했습니다. 내가 그것을 실행하고 응답을 반향하는 것은 괜찮아 보인다. 코드는 다음과 같습니다 나는 (버튼을 클릭) 실행하면
<!DOCTYPE html>
<head>
<meta h**p-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="h**ps://www.paypalobjects.com/api/checkout.js"></script>
</head>
<body>
<div id="paypal-button-container"></div>
<script>
paypal.Button.render({
env: 'sandbox', // sandbox | production
commit: true,
payment: function() {
// Set up a url on your server to create the payment
var CREATE_URL = 'h**ps://MySite.com/PayPalRest/first.php';
// Make a call to your server to set up the payment
console.log(paypal.request.post(CREATE_URL));
return paypal.request.post(CREATE_URL)
.then(function(res) {
return res.paymentID;
});
},
// onAuthorize() is called when the buyer approves the payment
onAuthorize: function(data, actions) {
// Set up a url on your server to execute the payment
var EXECUTE_URL = '/demo/checkout/api/paypal/payment/execute/';
// Set up the data you need to pass to your server
var data = {
paymentID: data.paymentID,
payerID: data.payerID
};
// Make a call to your server to execute the payment
return paypal.request.post(EXECUTE_URL, data)
.then(function (res) {
window.alert('Payment Complete!');
});
}
}, '#paypal-button-container');
</script>
</body>
는 라이트가에 대한 팝업 :
<?php
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
require __DIR__ . '/PayPal-PHP-SDK/autoload.php';
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
// 2. Provide your Secret Key. Replace the given one with your app clientId, and Secret
// h**ps://developer.paypal.com/webapps/developer/applications/myapps
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'ClientID IS HERE AND IS CORRECT', // ClientID
'Secret IS HERE AND IS CORRECT' // ClientSecret
)
);
// 3. Lets try to create a Payment
// h**ps://developer.paypal.com/docs/api/payments/#payment_create
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');
/*$amount = new \PayPal\Api\Amount();
$amount->setTotal('1.00');
$amount->setCurrency('USD');*/
$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')
->setCurrency('USD')
->setQuantity(1)
->setPrice(7.5);
$item2 = new Item();
$item2->setName('Granola bars')
->setCurrency('USD')
->setQuantity(5)
->setPrice(2);
$itemList = new ItemList();
$itemList->setItems(array($item1, $item2));
//Additional payment details
//Use this optional field to set additional payment information such as tax, shipping charges etc.
$details = new Details();
$details->setShipping(1.2)
->setTax(1.3)
->setSubtotal(17.50);
//Amount
//Lets you specify a payment amount. You can also specify additional details such as shipping, tax.
$amount = new Amount();
$amount->setCurrency("USD")
->setTotal(20)
->setDetails($details);
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);
$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl("h**ps://example.com/your_redirect_url.html")
->setCancelUrl("h**ps://example.com/your_cancel_url.html");
$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions(array($transaction))
->setRedirectUrls($redirectUrls);
// 4. Make a Create Call and print the values
try {
$payment->create($apiContext);
// echo "\n\nRedirect user to approval_url: " . $payment->getApprovalLink() . "\n";
}
catch (\PayPal\Exception\PayPalConnectionException $ex) {
// This will print the detailed information on the exception.
//REALLY HELPFUL FOR DEBUGGING
echo $ex->getData();
}
return($payment);
?>
나는 이것이 내가 그들의 샘플 코드를 사용하여 버튼 스크립트를 생성
다음 작동합니다 생각 몇 초 후에 사라집니다. 그 사람이 자신의 계좌를 확인하고 지불 할 기회가 없습니다.
모든 SDK를 통해 읽었으며 문제가없는 샘플을 얻을 수 있습니다. 나는 지불 코드 반환이 틀린 것이어야한다고 생각한다. 어떤 제안을하면 어떻게 디버그 할 것인가는 정말 훌륭 할 것이다.
긴 게시물을 위해 죄송합니다.