|
if (!function_exists('new_post_paypal'))
{
/**
* paypal 支付
*/
function new_post_paypal($paypal, $title, $order)
{
$paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
$hb = 'USD';
$url = url('home/Index/paypal_returns', '', true, true);
$cancel = url('user/Shop/shop_centre', '', true, true);
$html = '';
$html .= '<form action="' . $paypal_url . '" method="post" name="E_FORM">';
$html .= '<input type="hidden" name="cmd" value="_xclick">';
// 商家邮箱
$html .= '<input type="hidden" name="business" value="' . $paypal . '">';
// 订单名称
$html .= '<input type="hidden" name="item_name" value="' . $title . '">';
// 订单号
$html .= '<input type="hidden" name="item_number" value="' . $order['order_code'] . '">';
// 金额
$html .= '<input type="hidden" name="amount" value="' . $order['money'] . '">';
// 货币
$html .= '<input type="hidden" name="currency_code" value="' . $hb . '">';
// 支付成功后网页跳转地址
$html .= '<input type="hidden" name="return" value="' . $url . '?payok=payok">';
// 支付成功后paypal后台发送回调地址
$html .= '<input type="hidden" name="notify_url" value="' . $url . '">';
// 用户取消交易返回地址
$html .= '<input type="hidden" name="cancel_return" value="' . $cancel . '">';
// 发票编码
$html .= '<input type="hidden" name="invoice" value="' . $order['order_code'] . '">';
// 字符集
$html .= '<input type="hidden" name="charset" value="utf-8">';
// 是否返回客户收货地址
$html .= '<input type="hidden" name="no_shipping" value="1">';
$html .= '<input type="hidden" name="rm" value="2">';
$html .= '</form>';
$html .= '<script>document.forms["E_FORM"].submit();</script>';
return $html;
}
}
if (!function_exists('paypal_return'))
{
/**
* 订单处理
*/
function paypal_return()
{
// 返回示例
// {"payer_email":"amirarobalino332@gmail.com","payer_id":"CBEGUPT9F5GQ6","payer_status":"UNVERIFIED","first_name":"Amira","last_name":"Robalino","txn_id":"5ME632201M506833T","mc_currency":"USD","mc_fee":"0.48","mc_gross":"3.99","protection_eligibility":"ELIGIBLE","payment_fee":"0.48","payment_gross":"3.99","payment_status":"Completed","payment_type":"instant","handling_amount":"0.00","shipping":"0.00","item_name":"Order 171807489512","quantity":"1","txn_type":"web_accept","payment_date":"2024-06-11T03:01:36Z","receiver_id":"QR4D5K3C6DMRC","notify_version":"UNVERSIONED","invoice":"171807489512","verify_sign":"AnJ2HUJsm40z244.ABNEwFR12hcFAVKCEACWfzcri8Dj.khTiqZRihvh"}
$input = $_POST;
$pay_type = 'paypal';
$ml = $pay_type . '/' . date('Y-m-d') . '/';
if ( ! is_dir($ml) ) {
mkdir($ml, 0777, true);
}
file_put_contents($ml . time() . '-1.txt', json_encode($input));
if (empty($input['invoice']) || empty($input['payment_status']) || empty($input['mc_gross'])) {
return false;
}
$payment_status = $input['payment_status']; // 返回状态
$mc_gross = $input['mc_gross'];
// 查询订单
$order = \think\Db::name('shop_order')->where(['order_code' => $input['invoice']])->find();
if ($payment_status == 'Completed' && $mc_gross == $order['order_amount']) {
// 支付成功处理
}
if ( isset($input['verify_sign']) ) {
return true;
}
return 'Success';
}
}
|
|