这是我的paypal计划,首先我创建了一个订单并获得了订单ID
然后创建PayPal付款
当用户完成付款时,我怎么知道付款是针对哪个订单ExecutePayment
?
//create customer's order and get the order id
$orderId=insertToDatabase();
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')
->setCurrency('USD')
->setQuantity(1)
->setSku("123123") // Similar to `item_number` in Classic API
->setPrice(7.5);
$item2 = new Item();
$item2->setName('Granola bars')
->setCurrency('USD')
->setQuantity(5)
->setSku("321321") // Similar to `item_number` in Classic API
->setPrice(2);
$itemList = new ItemList();
$itemList->setItems(array($item1, $item2));
$details = new Details();
$details->setShipping(1.2)
->setTax(1.3)
->setSubtotal(17.50);
$amount = new Amount();
$amount->setCurrency("USD")
->setTotal(20)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber(uniqid());
$baseUrl = 'http://site/paypal';
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment?success=true")
->setCancelUrl("$baseUrl/ExecutePayment?success=false");
$payment = new Payment();
$payment->setIntent("sale")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
try {
$apiContext = getApiContext('11111', '2222');
$payment->create($apiContext);
} catch (Exception $ex) {
var_dump($ex);
exit(1);
}
$approvalUrl = $payment->getApprovalLink();
echo "Created Payment Using PayPal. Please visit the URL to Approve.";
echo "<a href='$approvalUrl' >$approvalUrl</a>";
答案 0 :(得分:1)
在回复网址中定义订单变量
$baseUrl = 'http://site/paypal';
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment?success=true&orderid=1")
->setCancelUrl("$baseUrl/ExecutePayment?success=false&orderid=1");