我使用PayPal Rest API创建了一个PHP脚本。当我完成付款时,网站会重定向到带有付款成功标签的完成页面,但是当我访问沙盒paypal网站时,我看不到任何交易。我能做些什么来解决这个问题?
这里有3个脚本:
start.php
<?php
require 'vendor/autoload.php';
define('SITE_URL', 'http://192.168.1.105/Fenix/Include/pay.php');
$paypal = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'AX5IC3G3s-XRzfMgmSUjEPGbHAjD6PL80skf7Xck50OKWXQ2nGf-9NWk5FjSaMCh1FPpxFvUioqZEbjy',
'EJ8GDd08PwnRM1VxYzT2-fBmxAYzykYZ_zlwHi_zqmFGOQzaoXHAffM5DSiBDTcd8L6OpyDzGt5gtmMU'
)
);
&GT;
checkout.php
<?php
include "./vendor/autoload.php";
use PayPal\Api\Payer;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Payment;
require 'start.php';
/*
if (!isset($_POST['product'], $_POST['price'])){
die();
}
*/
$product = "Fenix ID";
$price = 0.01;
$shipping = 0;
$total = $price+$shipping;
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item = new Item();
$item->setName($product)
->setCurrency('EUR')
->setQuantity(1)
->setPrice($price);
$itemList = new ItemList();
$itemList->setItems([$item]);
$details = new Details();
$details->setShipping($shipping)
->setSubtotal($price);
$amount = new Amount();
$amount->setCurrency('EUR')
->setTotal($total)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription('Fenix ID')
->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(SITE_URL . '/pay.php?success=true')
->setCancelUrl(SITE_URL . '/pay.php?success=false');
$payment = new Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions([$transaction]);
try {
$payment->create($paypal);
}catch (Exception $e){
die($e);
}
$approvalUrl = $payment->getApprovalLink();
header("Location: {$approvalUrl}");
&GT;
pay.php
<?php
use PayPal\Api\Payment;
use PayPal\Api\PaymentExecution;
require 'start.php';
if (!isset($_GET['success'], $_GET['paymentId'], $_GET['PayerID'])) {
die();
}
if ((bool)$_GET['success'] === false) {
die();
}
$paymentId = $_GET['paymentId'];
$payment = Payment::get($paymentId, $paypal);
$execution = new PaymentExecution();
$execution->setPayerId($_GET['PayerID']);
echo "Payment success!";
&GT;
感谢您的帮助。