簡體   English   中英

PHP代碼以使用Payflow Pro退款

[英]PHP code to refund a charge with Payflow Pro

沒有用於PayPal Payflow Pro的PHP SDK。 如何使用PHP退款Payflow Pro信用卡費用? 如何做到這一點,以使我們符合PCI標准,而無需使用信用卡號?

這是一些使用curl來退還信用卡費用的PHP代碼。 此代碼基於Radu Manole的SDK。 有關更多信息,請參閱《 Payflow Pro開發人員指南》: https : //www.paypalobjects.com/webstatic/zh_CN/developer/docs/pdf/pp_payflowpro_guide.pdf

$user = 'CHANGEME'; // API User Username
$password = 'CHANGEME'; // API User Password
$vendor = 'CHANGEME'; // Merchant Login ID

// Reseller who registered you for Payflow or 'PayPal' if you registered
// directly with PayPal
$partner = 'PayPal'; 

$sandbox = true;

$transactionId = 'CHANGEME'; // The PNREF # returned when the card was charged
$amount = '3';
$currency = 'USD';

$url = $sandbox ? 'https://pilot-payflowpro.paypal.com'
  : 'https://payflowpro.paypal.com';

$params = array(
  'USER' => $user,
  'VENDOR' => $vendor,
  'PARTNER' => $partner,
  'PWD' => $password,
  'TENDER' => 'C', // C = credit card, P = PayPal
  'TRXTYPE' => 'C', //  S=Sale, A= Auth, C=Credit, D=Delayed Capture, V=Void                        
  'ORIGID' => $transactionId,
  'AMT' => $amount,
  'CURRENCY' => $currency
);

$data = '';
$i = 0;
foreach ($params as $n=>$v) {
    $data .= ($i++ > 0 ? '&' : '') . "$n=" . urlencode($v);
}

$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$headers[] = 'Content-Length: ' . strlen($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
curl_close($ch);

// Parse results
$response = array();
$result = strstr($result, 'RESULT');    
$valArray = explode('&', $result);
foreach ($valArray as $val) {
  $valArray2 = explode('=', $val);
  $response[$valArray2[0]] = $valArray2[1];
}

print_r($response);

if (isset($response['RESULT']) && $response['RESULT'] == 0) {
  echo 'SUCCESS!';
} else {
  echo 'FAILURE: ' . $response['RESPMSG'] . ' ['. $response['RESULT'] . ']';
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM