简体   繁体   English

我怎么知道支付宝的付款顺序?

[英]How can I know which order for the paypal payment?

This is my paypal program, first I create an order and get the order id 这是我的贝宝程序,首先我创建一个订单并获取订单ID

Then create the payment to paypal 然后创建付款给贝宝

When user finish the payment, how can I know that payment is for which order at ExecutePayment ? 当用户完成付款后,我如何知道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>";

Define the order variable in your return URL 在返回网址中定义订单变量

$baseUrl = 'http://site/paypal';
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment?success=true&orderid=1")
    ->setCancelUrl("$baseUrl/ExecutePayment?success=false&orderid=1");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM