【问题标题】:How can I know which order for the paypal payment?我怎么知道paypal付款的顺序?
【发布时间】:2016-04-17 04:39:48
【问题描述】:

这是我的 paypal 程序,首先我创建一个订单并获取订单 ID

然后创建支付宝

当用户完成付款后,我如何知道付款是针对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>";

【问题讨论】:

    标签: php paypal payment-gateway paypal-ipn payment


    【解决方案1】:

    在返回 URL 中定义 order 变量

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

    【讨论】:

    • 如果我只是简单地在url中传递id,如何知道支付是真的完成?用户可能会猜到订单 id 并转到 ExecutePayment?success=true&orderid=1 以在我的系统中完成订单
    • 您可以扩展我提供的示例以任何方式实现它,例如代表您的订单的 GUID。
    • 我刚刚尝试使用 GUID 作为订单 ID,但仍然不安全。我在paypal登录时点击取消,然后它重定向到ExecutePayment?success=false&amp;orderguid=xxxxxx,我必须通过id来处理虚假情况下的订单。即使用户猜不到订单id,这个程序仍然不安全。
    猜你喜欢
    • 2019-02-05
    • 1970-01-01
    • 1970-01-01
    • 2018-04-03
    • 2013-05-11
    • 2015-12-05
    • 2016-10-15
    • 2014-11-03
    • 1970-01-01
    相关资源
    最近更新 更多