PayPal Express Checkout API

时间:2012-10-23 18:52:00

标签: php api paypal

我的网站上有一个小型商品购买商店,它使用PayPal Express Checkout API来完成付款。除了最终的API调用DoExpressCheckoutPayment()之外,我一切正常。我试图以几种不同的方式实现这些方法,但它们似乎都没有起作用。

这是我的success.php页面,其中api调用GetExpressCheckoutDetails()位于顶部,然后DoExpressCheckoutPayment()应该位于底部:

<script language="Javascript">

    function showFBWindow(s1, s2, s3, s4, s5)
    {
        url = "purchase-thankyou.php?name="+s1+"&email="+s2+"&code="+s3+"&id="+s4+"&token="+s5;
        newwindow=window.open(url,'name');
        if (window.focus) {newwindow.focus();}
    }


</script>

<?php
require_once("PayPal_API.php");

$Token      = $_GET["token"];
$PayerID    = $_GET["PayerID"];

$nvps = array();
$nvps["VERSION"] = "65.1";

// get details of transaction 
$nvps["METHOD"] = "GetExpressCheckoutDetails";
$nvps["TOKEN"] = $Token;
$response = RunAPICall($nvps); // Send the API call to PayPal.

?>

<html>
<head>
<title>Order Processed</title>
</head>
<body bgcolor="#ffffff">
<h1>THANK YOU!</h1>
<p>
<h1>Your order has been processed. Please follow the link below to complete your   payment</h1>
</p>
<p>

<?php
//outputArrayValues($response);
$id         = $_GET['PayerID'];
$token      = $response['TOKEN'];
$checkoutstatus = $response['CHECKOUTSTATUS'];
$timestamp      = $response['TIMESTAMP'];
$correlation_id = $response['CORRELATIONID'];
$acknowledgement    = $response['ACK'];
$version        = $response['VERSION'];
$build      = $response['BUILD'];
$e_mail_id      = $response['EMAIL'];
$payer_id       = $response['PAYERID'];
$payer_status   = $response['PAYERSTATUS'];
$first_name     = $response['FIRSTNAME'];
$last_name      = $response['LASTNAME'];
$cust_name      = $first_name." ".$last_name;
$country_code   = $response['COUNTRYCODE'];
$currency_code  = $response['CURRENCYCODE'];
$amount     = $response['AMT'];
$item_amt       = $response['ITEMAMT'];
$shipping_amt   = $response['SHIPPINGAMT'];
$handling_amt   = $response['HANDLINGAMT'];
$tax_amt        = $response['TAXAMT'];


// complete purchase by sending DoExpressCheckoutPayment
$nvps["METHOD"] = "DoExpressCheckoutPayment";
$nvps["TOKEN"] = $token;
$nvps["PAYMENTACTION"] = "Sale";
$nvps["PAYERID"] = $payer_id;
// Send the API call to PayPal.
$response = RunAPICall($nvps);

?>

<a href="#" 
onclick="showFBWindow('<?php echo $cust_name;?>','<?php echo $e_mail_id;?>','<?php echo     $currency_code; ?>','<?php echo $id;?>', '<?php echo $token;?>')">
   Click to Continue</a>

</body>
</html>

我将客户名称和电子邮件通过URL传递到感谢页面,以将信息保存到我的数据库中。我应该在感谢页面上拨打DoExpressCheckoutPayment()吗?

编辑:我已将{&amp; useraction = commit'添加到SetExpressCheckout() URL调用的末尾,该调用应该会使“继续”按钮更改为“立即付款”这是什么,但它仍然没有完成付款?

1 个答案:

答案 0 :(得分:0)

使用“useraction = commmit”不会消除调用DoExpressCheckoutPayment()调用的需要。正如您所注意到的 - 它只会改变体验,但不会短路API调用。更多信息:https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECCustomizing

回到原来的问题 - 不 - 你应该在显示“谢谢你页面”之前调用DoExpresscheckout直到你打电话给DoExpresscheckout - 你的资金不能保证。