public function paystack()
{
$secrct_key ='66464713****khkkkjll';
$url = "https://api.paystack.co/transaction/initialize";
$fields = [
'key'=>"214*******4646464",
'email' => "test@email.com",
'amount' => "1000",
'metadata'=>"1111",
];
$fields_string = http_build_query($fields);
//open connection
$key = 'Bearer'.' '.$secrct_key;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: $key",
"Cache-Control: no-cache",
));
//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//execute post
$result = curl_exec($ch);
$result = json_decode($result,true);
dump($result);
$url = $result['data']['authorization_url'];
if($result === false) {
// echo 'Curl error: ' . curl_error($ch);
self::showJson(array('status'=>0,'msg'=>curl_error($ch))); exit();
}else{
self::showJson(array('status'=>1,'msg'=>'请求成功','data'=>$url)); exit();
// Header("Location: $url");
}
}
/**
* 同步回调
*/
public function back()
{
$config = D('Api/Getplugmsg')->plug_config_get(24);
$secrct_key = $config['plug_config']['24']['secret_key'];
$key = 'Bearer' . ' ' . $secrct_key;
$reference = self::$postget['reference'];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.paystack.co/transaction/verify/$reference",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => array(
"Authorization: $key",
"Cache-Control: no-cache",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
header('location: http://' . $_GET['http_website_domain_name'] . '/index/pay-failure');//支付失败跳转
exit();
} else {
$response = json_decode($response, true);
// dump($response);die();
$paymsg_info = M('order_paymsg_record')->where(array('out_trade_no' => $reference))->find();
if ($response['message'] == 'Verification successful') {
$paymsg_info['returndata'] = json_encode($response);
$paymsg_info['status'] = 2;
$paymsg_info['paymsg'] = $paymsg_info['paytype'];
$pay = A('Home/Paypalrun')->deal_pay_msg($paymsg_info);
if ($pay == 12) {
header('location: http://' . $_GET['http_website_domain_name'] . '/index/pay-success');//支付成功
} else {
header('location: http://' . $_GET['http_website_domain_name'] . '/index/pay-failure');//支付失败
}
}
}
}
//异步回调
public function webback()
{
$file_post=[];
$file_post['input'] = file_get_contents("php://input");
$file_post['event'] = json_decode($file_post);
$file_post['get'] = $_GET;
$file_post['post'] = $_POST;
$file_post['myslef'] = self::$postget;
file_put_contents('./Public/2222.txt',json_encode($file_post),FILE_APPEND);
dump('222');
http_response_code(200);
}
paystack支付
最新推荐文章于 2024-06-14 09:37:51 发布