2013-10-29 76 views
0

正在使用以下代碼進行訂閱。但是,我沒有得到TXN_ID這個交易.....請幫助。爲了取消目的,txn_id是必需的。

***Subscription HTML*** 
<form name="paypal" id="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr"> 
<input type="hidden" name="cmd" value="_xclick-subscriptions"> 
<input type="hidden" name="business" value="[email protected]"> 
<input type="hidden" name="cmd" value="_xclick-subscriptions"> 
<input type="hidden" name="currency_code" value="USD"> 
<input type="hidden" name="a3" value="2.00"> 
<input type="hidden" name="p3" value="3"> 
<input type="hidden" name="t3" value="M"> 
<input type="hidden" name="return" value="subscription.php?sus=sus&cid=201"> 
<input type="hidden" name="cancel_return" value="subscription.php?can=can"> 
<input type="hidden" name="no_shipping" value="1"> 
<input type="hidden" name="rm" value="2"> 
<input type="hidden" name="item_name" value="Test Subscription"> 
<input type="hidden" name="item_number" value="Subscription"> 
<input type="hidden" value="Please go back to website ..." name="cbt"> 

正在使用下面的代碼取消&退款amound 取消代碼。

function change_subscription_status($tran_id,$amount) { 
$version  = urlencode('51.0'); 
$API_Password = urlencode('1111111111'); 
$API_UserName = urlencode('xxxxxxxxxxx_biz_api1.gmail.com'); 
$transactionID = urlencode($tran_id); 
$refundType  = urlencode('Partial'); 
$amount   = $amount; 
$currencyID  = urlencode('USD'); 
$API_Signature = urlencode('xxxxxxxxxxxxxxxxxxxxxxxxx'); 
$nvpStr   = "&TRANSACTIONID=$transactionID&REFUNDTYPE=$refundType&AMT=$amount&CURRENCYCODE=$currencyID"; 
$api_request = "METHOD=RefundTransaction&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp'); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
// Turn off the server and peer verification (TrustManager Concept). 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POST, 1); 
// Set the request as a POST FIELD for curl. 
curl_setopt($ch, CURLOPT_POSTFIELDS, $api_request); 
// Get response from the server. 
$httpResponse = curl_exec($ch); 
curl_close($ch); 
if(!$httpResponse) { 
exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')'); 
} 
// Extract the response details. 
return $httpResponseAr = explode("&", $httpResponse); 
} 

回答

0

當您設置了協議,它不會給你一個txn_id因爲你沒有在技術上得到任何。你需要設置一個IPN監聽器,當它爲你付費時,你可以從中獲得txn_id。然後你可以做你的退款。

+0

感謝您的回覆。你能發送IPN Listerner Code嗎? –

+0

https://developer.paypal.com/webapps/developer/docs/classic/ipn/gs_IPN/ – Machavity