簡體   English   中英

paypal大規模支付api在php中使用

[英]paypal mass payment api use in php

我正在嘗試使用此代碼使用Paypal Mass Payment API,但我收到此錯誤。

我將此代碼保存到文件'MassPay.php'並將其上傳到我的localhost。 我正在嘗試測試代碼,如果我可以使它工作,我會在核心php中使用它,每月大規模支付教師。

Array
(
    [TIMESTAMP] => 2015-07-03T06:55:19Z
    [CORRELATIONID] => 437cfd2eedc02
    [ACK] => Failure
    [VERSION] => 74.0
    [BUILD] => 17235934
    [L_ERRORCODE0] => 10004
    [L_SHORTMESSAGE0] => Transaction refused because of an invalid argument. See additional error messages for details.
    [L_LONGMESSAGE0] => The number of input records is less than or equal to zero
    [L_SEVERITYCODE0] => Error
    [ERRORS] => Array
        (
            [0] => Array
                (
                    [L_ERRORCODE] => 10004
                    [L_SHORTMESSAGE] => Transaction refused because of an invalid argument. See additional error messages for details.
                    [L_LONGMESSAGE] => The number of input records is less than or equal to zero
                    [L_SEVERITYCODE] => Error
                )

        )

    [REQUESTDATA] => Array
        (
            [USER] => dudhat-facilitator_api1.artoongames.com
            [PWD] => AXAT8HSZRR4XANFZ
            [VERSION] => 74.0
            [BUTTONSOURCE] => AngellEYE_PHPClass
            [SIGNATURE] => AFcWxV21C7fd0v3bYYYRCpSSRl31Ab1QV5bWA6uEZ.6emUAkZaZEhjiA
            [METHOD] => MassPay
            [EMAILSUBJECT] => dudhat@artoongames.com
            [CURRENCYCODE] => USD
            [RECEIVERTYPE] => EmailAddress
        )

    [RAWREQUEST] => USER=dudhat-facilitator_api1.artoongames.com&PWD=AXAT8HSZRR4XANFZ&VERSION=74.0&BUTTONSOURCE=AngellEYE_PHPClass&SIGNATURE=AFcWxV21C7fd0v3bYYYRCpSSRl31Ab1QV5bWA6uEZ.6emUAkZaZEhjiA&METHOD=MassPay&EMAILSUBJECT=dudhat%40artoongames.com&CURRENCYCODE=USD&RECEIVERTYPE=EmailAddress
    [RAWRESPONSE] => TIMESTAMP=2015%2d07%2d03T06%3a55%3a19Z&CORRELATIONID=437cfd2eedc02&ACK=Failure&VERSION=74%2e0&BUILD=17235934&L_ERRORCODE0=10004&L_SHORTMESSAGE0=Transaction%20refused%20because%20of%20an%20invalid%20argument%2e%20See%20additional%20error%20messages%20for%20details%2e&L_LONGMESSAGE0=The%20number%20of%20input%20records%20is%20less%20than%20or%20equal%20to%20zero&L_SEVERITYCODE0=Error
)

使用此代碼“MassPay.php”

<?php

// Include required library files.
require_once('includes/config.php');
require_once('includes/paypal.class.php');

// Create PayPal object.
$PayPalConfig = array('Sandbox' => $sandbox, 'APIUsername' => $api_username, 'APIPassword' => $api_password, 'APISignature' => $api_signature);
$PayPal = new PayPal($PayPalConfig);

// Prepare request arrays
$MPFields = array(
    'emailsubject' => 'dudhat@artoongames.com', // The subject line of the email that PayPal sends when the transaction is completed.  Same for all recipients.  255 char max.
    'currencycode' => 'USD', // Three-letter currency code.
    'receivertype' => 'EmailAddress'       // Indicates how you identify the recipients of payments in this call to MassPay.  Must be EmailAddress or UserID
);

// Typically, you'll loop through some sort of records to build your MPItems array. 
// Here I simply include 3 items individually.  

$Item1 = array(
    'l_email' => 'dudhat@gmail.com', // Required.  Email address of recipient.  You must specify either L_EMAIL or L_RECEIVERID but you must not mix the two.
    'l_receiverid' => 'dudhat@gmail.com', // Required.  ReceiverID of recipient.  Must specify this or email address, but not both.
    'l_amt' => '10.00', // Required.  Payment amount.
    'l_uniqueid' => '522', // Transaction-specific ID number for tracking in an accounting system.
    'l_note' => 'test payment'         // Custom note for each recipient.
);

$Item2 = array(
    'l_email' => 'dilip@gmail.com', // Required.  Email address of recipient.  You must specify either L_EMAIL or L_RECEIVERID but you must not mix the two.
    'l_receiverid' => 'dilip@gmail.com', // Required.  ReceiverID of recipient.  Must specify this or email address, but not both.
    'l_amt' => '1.00', // Required.  Payment amount.
    'l_uniqueid' => '523', // Transaction-specific ID number for tracking in an accounting system.
    'l_note' => 'test payment'         // Custom note for each recipient.
);



$MPItems = array($Item1,$Item2);  // etc

$PayPalRequestData = array('MPFields' => $MPFields, 'MPItems' => $MPFields);

// Pass data into class for processing with PayPal and load the response array into $PayPalResult
$PayPalResult = $PayPal->MassPay($PayPalRequestData);

// Write the contents of the response array to the screen for demo purposes.
echo '<pre />';
print_r($PayPalResult);
?>

您在$ MPItems中匯總了一些付款項目,但沒有將$ MPItems添加到PayPal請求數據中。 因此,PayPal拒絕批量付款,因為不包含任何付款項目。

您可以使用以下課程進行大額工資交易

用實際的paypal憑證模式(live / sandbox)定義你的常量。

class PaypalnvpComponent {

    private static $API_Username = PAYPAL_API_USERNAME;
    private static $API_Password = PAYPAL_API_PASSWORD;
    private static $API_Signature = PAYPAL_API_SIGNATURE;
    private static $API_Environment = PAYPAL_API_MODE;
    private static $API_Version = '116.0';

    public static function Call($methodName,$params){
        if(self::$API_Environment == 'LIVE'){
            $API_Endpoint = "https://api-3t.paypal.com/nvp";            
        }else{
            $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
        }

        $nvpstr = "";
        foreach($params as $k=>$v){
            $nvpstr .="&".$k."=".urlencode($v);
        }

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);

        //Turn of server and pakagemanager
        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 API operation,version,API signature in requrest

        $nvpreq ="";
        $nvpreq .= "METHOD=".urlencode($methodName);
        $nvpreq .= "&VERSION=".urlencode(self::$API_Version);
        $nvpreq .= "&PWD=".urlencode(self::$API_Password);
        $nvpreq .= "&USER=".urlencode(self::$API_Username);
        $nvpreq .= "&SIGNATURE=".urlencode(self::$API_Signature);
        $nvpreq .= $nvpstr;

        //set the request as POST field for curl
        curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

        //get the response from server
        $httpResponse = curl_exec($ch);

        if(!$httpResponse){
            return "$methodName failed:".curl_error($ch).'('.curl_errno($ch).')';
        }

        //Extract the response details

        $httpResponseArray = explode('&', $httpResponse);

        $httpParsedResponseArray = array();

        foreach ($httpResponseArray as $i=>$value){
            $tmpArray = explode('=', $value);
            if(sizeof($tmpArray) > 1){
                $httpParsedResponseArray[$tmpArray[0]] = urldecode($tmpArray[1]);
            }
        }
        if((0 == sizeof($httpParsedResponseArray)) || !array_key_exists('ACK',$httpParsedResponseArray)){
            return "Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.";

        }
        return $httpParsedResponseArray;        
    }


    #----------------------------
    # @$hok
    # mass payment with multiple users in one go
    # paypal transaction status will be : Completed, Failed, Returned, Reversed, Unclaimed, Pending, Blocked
    #----------------------------
    public static function MassPay($params){
        $methodName = "MassPay";        
        return self::Call($methodName, $params);
    }

    public static function GetTransactionDetail($params){
        $methodName = "GetTransactionDetails";        
        return self::Call($methodName, $params);        
    }

    public static function TransactionSearch($params){
        $methodName = "TransactionSearch";        
        return self::Call($methodName, $params);        
    }
}

# below is the example how to use above class
$params = array();
$params["RECEIVERTYPE"] = "EmailAddress";
$params["EMAILSUBJECT"] = "Your withdraw request was processed";

$params["L_AMT0"] = 1;
$params["L_EMAIL0"] = "xyz@xyz.abc"; 
$params["L_UNIQUEID0"] = rand(11111,9999999);

$params["L_AMT1"] = 2;
$params["L_EMAIL1"] = "hamed-buyer@lifeofu.com"; 
$params["L_UNIQUEID1"] = rand(11111,9999999);

$params["L_AMT2"] = 3;
$params["L_EMAIL2"] = "testuser1@test1.com"; 
$params["L_UNIQUEID2"] = rand(11111,9999999);

$params["CURRENCYCODE"] = "USD";       

$result = PaypalnvpComponent::MassPay($params);


//transaction detial  
$params = array();
$params["TRANSACTIONID"] = TRANSACTIONID_HERE; 
$result = PaypalnvpComponent::GetTransactionDetail($params);

暫無
暫無

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

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