जैसा कि मैंने किसी को भी किसी भी समाधान नहीं मिला तो मैं कदम और पाया समाधान के आधार पर अपने कोड कदम में खोदे गए।
function paypalFuturePayment($userID,$amount)
{
$amount=number_format($amount,2);
/* paypal App truxx dev client and secret key*/
if($userID && $amount){
$userData = selectById('tbl_users','*',"id='".$userID."'");
$refresh_token = $userData['paypal_refresh_tokens'];
$Metadata_id = $userData['paypal_metadata_id'];
if($refresh_token && $Metadata_id){
if ($_SERVER['SERVER_NAME'] == 'syonserver.com') {
$clientId = "xxxxx";
$secret = "xxx";
$url1="https://api.sandbox.paypal.com/v1/oauth2/token";
$url2="https://api.sandbox.paypal.com/v1/payments/payment";
}else{
$account = 0; // 0 for sandbox ,1 for live
if ($account == 1) {
//client live
$clientId = "xxx";
$secret = xxx";
$url1 = "https://api.paypal.com/v1/oauth2/token";
$url2 = "https://api.paypal.com/v1/payments/payment";
} else {
//client sandbox
$clientId = "xxx";
$secret = "xxx";
$url1 = "https://api.sandbox.paypal.com/v1/oauth2/token";
$url2 = "https://api.sandbox.paypal.com/v1/payments/payment";
}
}
//print_r($refresh_token);die;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_HEADER, "Content-Type: application/x-www-form-urlencoded");
curl_setopt($ch, CURLOPT_USERPWD, $clientId . ":" . $secret);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=refresh_token&refresh_token=" . $refresh_token);
$result = curl_exec($ch);
curl_close($ch);
$result=json_decode($result);
//11111111 for payment Authorize: For example, to first authorize the payment, use a request similar to this:
$access_token = $result->access_token;
$data = array(
"intent" => "authorize",
"payer" => array(
"payment_method" => "paypal"
),
"transactions" => array(
array("amount" => array(
"currency" => "USD",
"total" => $amount
),
"description" => "future of sauces")
));
$data_string = json_encode($data);
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, $url2);
$headers = array(
'Content-Type: application/json',
'PayPal-Client-Metadata-Id: '.$Metadata_id,
'Authorization: Bearer '.$access_token,
'Content-Length: ' . strlen($data_string)
);
curl_setopt($ch1, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch1, CURLOPT_POST, true);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_POSTFIELDS, $data_string);
$result1 = curl_exec($ch1);
curl_close($ch1);
$result1=json_decode($result1);
$message = $result1->message;
if($result1->state=='approved'){
$access_id= $result1->transactions[0]->related_resources[0]->authorization->id;
}else{
if(empty($message)){
$message ='Authorization error, Please try again.';
}
return array('response' => '', 'success' => '0','message'=>$message);
}
// print_r($result1);die;
//2222222 capture the payment:
$data = array("amount" => array(
"currency" => "USD",
"total" => $amount
),
"is_final_capture" => "true"
);
$data_string = json_encode($data);
$ch2 = curl_init();
if ($_SERVER['SERVER_NAME'] == 'syonserver.com') {
curl_setopt($ch2, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/authorization/$access_id/capture");
}else {
$account = 0; // 0 for sandbox ,1 for live
if ($account == 1) {
//client live
curl_setopt($ch2, CURLOPT_URL, "https://api.paypal.com/v1/payments/authorization/$access_id/capture");
}else{
curl_setopt($ch2, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/authorization/$access_id/capture");
}
}
$headers = array(
'Content-Type: application/json',
'Authorization: Bearer '.$access_token,
'Content-Length: ' . strlen($data_string)
);
curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch2, CURLOPT_POST, true);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $data_string);
$response = curl_exec($ch2);
curl_close($ch2);
$response_a = json_decode($response, true);
$state = $response_a['state'];
$message = $response_a['message'];
if(!empty($response_a)){
if($state=='completed') {
return array('response' => $response_a, 'success' => '1','message'=>'Data received');
}else{
if(empty($message)){
$message ='Payment authorization error, Please try again.';
}
return array('response' => '', 'success' => '0','message'=>$message);
}
}
else{
return array('response' => '','success'=>'0','message'=>'Response nil');
}
}
else
{
return array('response' => '', 'success' => '0','message'=>'Authorization code not available.');
}
}else{
return array('response' => '', 'success' => '0','message'=>'Unauthorize request.');
}
}
जिज्ञासा से, क्या पेपैल एसडीके का उपयोग करने के लिए एक निश्चित विचलन है? यह बहुत से संभालता है, और स्थिरता सुनिश्चित करता है। मैं पूछता हूं क्योंकि मैं अनुरोध में * वैध * क्लाइंट आईडी और गुप्त दोनों को नहीं देख रहा हूं - मुझे लगता है कि आपको त्रुटियां मिल रही हैं। आईडी बहुत छोटी दिखती है (शायद आपने इसे संपादित किया है, यदि हां, तो इसे अवहेलना करें)। –
उसे अनुरोध में एक भालू टोकन मिला है - जब तक भालू टोकन की समयसीमा समाप्त नहीं हो जाती है तब तक वैध होना चाहिए। –
यदि आप इसे नहीं पढ़ते हैं तो आप इसे देख सकते हैं: https://developer.paypal.com/docs/integration/mobile/make-future-payment/, 'एथ कोड प्राप्त करें' – HardikDG