在Payflow定期付款中被批准为[RESPMSG],但PayPal帐户中没有交易记录

时间:2016-12-16 08:15:29

标签: php paypal payment-gateway paypal-sandbox payflowpro

我试图在沙箱模式下使用Payflow进行一次并重复付款。

这是我的代码:

$sandbox = TRUE;
$api_endpoint = 'https://pilot-payflowpro.paypal.com';

$VENDOR = '***abcd';
$PARTNER = 'PayPal';
$PWD = '**ab#$12345';
$USER = '***abcd';
$secureTokenId = uniqid('', true);

if ($payment_type == 'Non Recurring') {
    // Store request params in an array
    $request_params = array
    (
        'USER' => $USER,
        'PWD' => $PWD, 
        'PARTNER' => $PARTNER,
        'VENDOR' => $VENDOR,
        'TRXTYPE' => 'A',  
        'TENDER'=> 'C',
        'ACTION' => 'A',  
        'ACCT' => $results[0]->cerditcardno, 
        'AMT' => $price, 
        'EXPDATE' => $results[0]->cardexpiresmounth.$results[0]->cardexpiresyear, 
        'CVV2' => $results[0]->cvc,            
        'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
        'FIRSTNAME' => $results[0]->display_name, 
        'LASTNAME' =>  $results[0]->lastname, 
        'STREET' => $results[0]->Address, 
        'CITY' => $results[0]->city,
        'STATE' => $results[0]->state,                     
        'COUNTRYCODE' => 'US', 
        'ZIP' => $results[0]->zipcode, 
        );

    // Loop through $request_params array to generate the NVP string.
    $nvp_string1 = '';
    foreach($request_params as $var=>$val){
        $nvp_string1 .= '&'.$var.'='.$val;
    }
    $nvp_string = substr($nvp_string1, 1);

    // Send NVP string to PayPal and store response
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_VERBOSE, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($curl, CURLOPT_TIMEOUT, 60);
    curl_setopt($curl, CURLOPT_URL, $api_endpoint);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);

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

    $paypalResponse = array();
    parse_str($result, $paypalResponse);

    $paypal_result = $paypalResponse['RESULT'];
    $securetoken = $paypalResponse['SECURETOKEN'];
    $securetoken_id = $paypalResponse['SECURETOKENID'];
    $respmsg = $paypalResponse['RESPMSG'];
    $payload=json_encode($paypalResponse);

    $paymenttable=$wpdb->prefix."payments";
    $insert_txn = "INSERT INTO $paymenttable(`txn_id`,`status`,`booking_id`,`amount`,`payload`,`timestamp`) VALUES ('$txn_id','$respmsg','$book_id','$amount','$payload',UNIX_TIMESTAMP(NOW()))";

    $insert_txn_query = $wpdb->query($insert_txn);

    // Parse the API response

    if($respmsg == 'Approved'){
        $bookingtable=$wpdb->prefix."booking";
        $wpdb->query("UPDATE $bookingtable SET subscription_status='Active' WHERE id='$booking_id'");
        $payment_success = 1;
    }
    else{
        $payment_success = 0;   
    }
}
else{

    if ($_POST['frequency_id'] == 'Every week' ) {
        $billing_period = 'Week';
        $billing_frequency = 52;
    }
    elseif ($_POST['frequency_id'] == 'Every 2 weeks') {
        $billing_period = 'SemiMonth';
        $billing_frequency = 1;
    }
    elseif ($_POST['frequency_id'] == 'Every 4 weeks') {
        $billing_period = 'Month';
        $billing_frequency = 12;
    }
    // Store request params in an array
    $request_params = array
    (
        'TRXTYPE' => 'A',
        'TENDER'=> 'C',
        'ACTION' => 'A',
        'VERBOSITY' => 'MEDIUM',
        'USER' => $USER,
        'PWD' => $PWD,
        'PARTNER' => $PARTNER,
        'VENDOR' => $VENDOR,
        'PROFILENAME' => 'RegularSubscription',
        'ACCT' => $results[0]->cerditcardno,
        'AMT' => $price,
        'EXPDATE' => $results[0]->cardexpiresmounth.$results[0]->cardexpiresyear,
        'CVV2' => $results[0]->cvc,
        'START' => date("mdY"),
        'TERM' => '0',
        'PAYPERIOD' => $billing_period, #Period of time between billings
        'MAXFAILEDPAYMENTS' => 3,    #Maximum failed payments before suspension of the profile
        'OPTIONALTRX' => 'S',
        'OPTIONALTRXAMT' => '2.00',
        'IPADDRESS' => $_SERVER['REMOTE_ADDR'],               
        'CREATESECURETOKEN' => 'Y',
        'SECURETOKENID' => $secureTokenId,
        'FIRSTNAME' => $results[0]->display_name, 
        'LASTNAME' =>  $results[0]->lastname, 
        'STREET' => $results[0]->Address, 
        'CITY' => $results[0]->city,
        'STATE' => $results[0]->state,                     
        'COUNTRYCODE' => 'US', 
        'ZIP' => $results[0]->zipcode,
    );

    // Loop through $request_params array to generate the NVP string.
    $nvp_string1 = '';
    foreach($request_params as $var=>$val){
        $nvp_string1 .= '&'.$var.'='.$val;
    }
    $nvp_string = substr($nvp_string1, 1);

    // setting the curl parameters.
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $api_endpoint);
    curl_setopt($curl, CURLOPT_VERBOSE, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // Make it true for live url.
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_TIMEOUT, 60);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);

    $result = curl_exec($curl); 
    // Check if any error occurred
    if(curl_errno($curl))
    {
        echo 'Curl error: ' . curl_error($curl);
    }
    curl_close($curl);

    $paypalResponse = array();
    parse_str($result, $paypalResponse);

    $paypal_result = $paypalResponse['RESULT'];
    $securetoken = $paypalResponse['SECURETOKEN'];
    $securetoken_id = $paypalResponse['SECURETOKENID'];
    $respmsg = $paypalResponse['RESPMSG'];

}

这是我收到的PayPal回复:

Array
(
    [RESULT] => 0
    [RESPMSG] => Approved
    [SECURETOKEN] => 9vaaCvieCA0arm7qBM87FrAgw
    [SECURETOKENID] => 5853a15a7716b1.59486056
)

但是,我没有获得任何交易ID,而且我无法在PayPal沙盒帐户中看到任何交易。此外,当我登录经理帐户时,在服务设置下没有定期结算的个人资料。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

我认为您正在通过CREATESECURETOKEN = Y来创建您不需要的个人资料。甚至是安全令牌ID。以下是用于创建定期配置文件的示例有效负载

<强>有效载荷:

TRXTYPE=R&TENDER=C&PARTNER=PayPal&VENDOR=Acme&USER=Acme&PWD=a1b2c3d4&ACTION=A
&PROFILENAME=RegularSubscription&AMT=42.00&ACCT=4012888888881881&EXPDATE=0203
&START=12012013&PAYPERIOD=WEEK&TERM=12&OPTIONALTRX=S&OPTIONALTRXAMT=2.00
&COMMENT1=First-time customer

<强>文档: https://developer.paypal.com/docs/classic/payflow/recurring-billing/