贝宝交易值$ keyarray ['item_name']变量不起作用

时间:2018-07-16 18:42:58

标签: php arrays paypal transactions eclipse-pdt

我在从Paypals事务回调返回item / items_name数组时遇到问题。当我添加值item_name1时,该代码有效,但这未返回购买的其他可能商品名称的值。

例如,$ item_name没有显示返回值,但是如果我使用$ item_name1,它将返回项目名称值1。

通常要返回一个数组,我使用$ item_name [0],但是它不起作用。我在Paypal网站上查看了变量$ item_namex,但仍无法正常工作。 当产品缺货或不再可用时,我需要这些值来更新mysql数据库 这是侦听器代码:

> <?php $pp_hostname = "www.paypal.com"; // Change to
> www.sandbox.paypal.com to test against sandbox // read the post from
> PayPal system and add 'cmd' $req = 'cmd=_notify-synch';   $tx_token =
> $_GET['tx']; $auth_token = "token_here"; $req .=
> "&tx=$tx_token&at=$auth_token";   $ch = curl_init(); curl_setopt($ch,
> CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr"); curl_setopt($ch,
> CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
> curl_setopt($ch, CURLOPT_POSTFIELDS, $req); curl_setopt($ch,
> CURLOPT_SSL_VERIFYPEER, 1); //set cacert.pem verisign certificate path
> in curl using 'CURLOPT_CAINFO' field here, //if your server does not
> bundled with default verisign certificates. curl_setopt($ch,
> CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_HTTPHEADER,
> array("Host: $pp_hostname")); $res = curl_exec($ch); curl_close($ch);
> if(!$res){
>     //HTTP ERROR }else{
>      // parse the data
>     $lines = explode("\n", trim($res));
>     $keyarray = array();
>     if (strcmp ($lines[0], "SUCCESS") == 0) {
>         for ($i = 1; $i < count($lines); $i++) {
>             $temp = explode("=", $lines[$i],2);
>             $keyarray[urldecode($temp[0])] = urldecode($temp[1]);
>         }
>     // check the payment_status is Completed
>     // check that txn_id has not been previously processed
>     // check that receiver_email is your Primary PayPal email
>     // check that payment_amount/payment_currency are correct
>     // process payment
>     $firstname = $keyarray['first_name'];
>     $lastname = $keyarray['last_name'];
>     $amount = $keyarray['mc_gross'];  $currency = $keyarray['mc_currency'];   $payer_email = $keyarray['payer_email'];
>   $address_street = $keyarray['address_street'];  $address_zip =
> $keyarray['address_zip'];     $address_city = $keyarray['address_city'];
>   $payment_date = $keyarray['payment_date'];  $payer_email =
> $keyarray['payer_email'];     $mc_shipping = $keyarray['mc_shipping'];
>   $mc_fee = $keyarray['mc_fee'];  $num_cart_items =
> $keyarray['num_cart_items'];  $residence_country =
> $keyarray['residence_country'];   $item_name = $keyarray['item_name'];
>      $message ="Thank you for your purchase, your transaction has been successful!     <br /> <br />";
> 
>    $message1 ="<b>Payment Details</b><br>\n
>     <li>Name: $firstname $lastname</li>\n
>     <li>Transaction id: $tx_token</li>\n    <li>Amount: $amount $currency</li>\n
>       <li>Item: $item_name</li>\n
>        <br /> for more information on your purchase You may log into your account at <a href='https://www.paypal.com'>www.paypal.com</a> to
> view details of this transaction. As we prepare yourIf you have any
> questions please contact us directly support@studio84m.com<br>
> 
> We aim to reply to any inquiry as soon as possible usually within
> 24hrs";
>    
>    
>     }
>     else if (strcmp ($lines[0], "FAIL") == 0) {
>        $message = "Opps, there was a problem!<br /> An error has occured. Please check your paypal account to see if the transaction
> was complete otherwise please go back to your cart and finish the
> purchase" ;
>     } }
> 
> ?>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<?php include('includes/header.php'); ?>
<?php include('includes/historybar1.php'); ?>
<div class="container">
<div id="g-container">
<div class="headline">

 <div id="xlhead" class="xlhead"><?php echo $message; ?></div>
<br />
<p><?php echo $message1; ?></p>
  </div>
<div id="g-content" class="g-row">
<div id="g-product" class="g-col">
<br>
</div></div>
<br>
</div>

</div>
<?php include('includes/footer.php'); ?>
</body>
</html>

请注意,“ token_here”已替换为我的令牌ID。在此先感谢

0 个答案:

没有答案
相关问题