paypal单笔支付空白回复

paypal single payout blank response

我想在我的系统中集成 paypal 的单一支付方式,因为我想在我的卖家要求提款时向他们汇款。我为此生成了一个 "Access token key" 并从 PHP 脚本进行了 curl 调用。但响应是一个空字符串。我试过 curl_error($curl); 但这也没有做任何事情。下面是我的代码

// 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' => 'myselle@gmail.com',
        '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);

但这里我的 $rep 是一个空白字符串,也尝试获取单次支付详细信息,但这也是 returns 空白字符串...请提前帮助..thanx。

经过2天的搜索,我找到了答案,非常简单。我没有使用 paypal 的单一支付,而是使用了 PAY API 的隐式支付操作。下面是它的代码..

 $receiver[] = array(
      'amount'  => '125.00',//amount to be transferred
      'email'  => 'seller@gmail.com',// 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' => 'admin.business@gmail.com', // 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 会将付款设置为隐式批准,而不会重定向到 PayPal。 (或者,您可以使用 sender.accountId。)