2017-04-21 106 views
0

我想在我的系統中整合paypal的單筆付款方式,因爲我想在請求退款時向我的賣家匯款。我爲此生成了一個「訪問令牌密鑰」,並從PHP腳本進行卷曲調用。但迴應是空白字符串。我試過curl_error($curl);,但這也沒有做任何事情。下面是我的代碼paypal單筆付款空白回覆

// data to be sent 
$data = [ 
      'sender_batch_header' => [ 
      'email_subject' => "You have a payment", 
      'sender_batch_id' => "125458268" 

      ], 
'items' => [ 
    [ 
     'recipient_type' => "EMAIL", 
     'amount' => [ 
      'value' => "12.00", 
      'currency' => "USD" 
     ], 
     'receiver' => '[email protected]', 
     'note' => 'A trial for single payout', 
     'sender_item_id' => "2014031400456" 
    ], 
], 
]; 

//curl link for single payout with sync off 
$curl = curl_init("https://api.sandbox.paypal.com/v1/payments/payouts?sync_mode=true"); 
$header = array(
    "Content-Type: application/json", 
    "Authorization: Bearer ".$access_token , 

); 

$options = array(
    CURLOPT_HTTPHEADER  => $header, 
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_SSL_VERIFYPEER => false, 
    CURLOPT_SSL_VERIFYHOST => false, 
    CURLOPT_POSTFIELDS => json_encode($values), 
    CURLOPT_CUSTOMREQUEST => "POST", 
    CURLOPT_TIMEOUT  => 10 
); 

curl_setopt_array($curl, $options); 
$rep = curl_exec($curl); 

$response = json_decode($rep, true); 
curl_close($curl); 

但在這裏我代表$是一個空字符串,試圖讓單一的支付細節爲好,但也將返回一個空字符串......請help..thanx提前。

回答

0

經過2天的搜索,我找到了一個答案,非常簡單。我沒有使用PayPal的單一付款,而是使用PayPal API的隱式付款操作。下面是它的代碼..

$receiver[] = array(
     'amount' => '125.00',//amount to be transferred 
     'email' => '[email protected]',// paypal email id to which you want to send money 
    ); 

$result = $paypal->call(
array(
'actionType' => 'PAY', 
'currencyCode' => 'USD', 
'feesPayer' => 'EACHRECEIVER', 
'memo' => 'Withdrawal request no. 356', 

'cancelUrl' => '/cancel.php', 
'returnUrl' => '/success.php', 
'senderEmail' => '[email protected]', // email id of admin's business account, from which amount will be transferred. 

'receiverList' => array(

    'receiver'=>$receiver 
) 

), 'Pay' 
); 

function call($values,$type) 
    { 
    $header = array(
    "X-PAYPAL-SECURITY-USERID: ".$config['userid'], 
    "X-PAYPAL-SECURITY-PASSWORD: ".$config['password'], 
    "X-PAYPAL-SECURITY-SIGNATURE: ".$config['signature'], 
    "X-PAYPAL-REQUEST-DATA-FORMAT: JSON", 
    "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON", 
    "X-PAYPAL-APPLICATION-ID: ".$config['appid']; 
    ); 

    $curl = curl_init("https://svcs.sandbox.paypal.com/AdaptivePayments/"); 
    $options = array(
    CURLOPT_HTTPHEADER  => $header, 
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_SSL_VERIFYPEER => false, 
    CURLOPT_SSL_VERIFYHOST => false, 
    CURLOPT_POSTFIELDS => json_encode($values), 
    CURLOPT_CUSTOMREQUEST => "POST", 
    CURLOPT_TIMEOUT  => 10 
); 
curl_setopt_array($curl, $options); 
$rep = curl_exec($curl); 
$response = json_decode($rep, true); 
curl_close($curl); 
return $response; 
    } 

如果您是API調用者和指定的SENDEREMAIL字段中輸入您的電子郵件地址,貝寶將隱式批准的支付,無需重新定向到PayPal。 (或者,您可以使用sender.accountId。)