1
This commit is contained in:
@@ -12,9 +12,11 @@ use PaypalServerSdkLib\Models\Builders\PaymentSourceBuilder;
|
||||
use PaypalServerSdkLib\Models\Builders\PaypalWalletBuilder;
|
||||
use PaypalServerSdkLib\Models\Builders\PaypalWalletExperienceContextBuilder;
|
||||
use PaypalServerSdkLib\Models\Builders\PurchaseUnitRequestBuilder;
|
||||
use PaypalServerSdkLib\Models\PaymentSource;
|
||||
use PaypalServerSdkLib\PaypalServerSdkClientBuilder;
|
||||
use think\Db;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\Env;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\Exception;
|
||||
use think\exception\DbException;
|
||||
@@ -49,6 +51,12 @@ class Order extends base{
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
if(isset($data['type'])&&$data['type']==2){
|
||||
$payType = 2;
|
||||
}else{
|
||||
$payType = 0;
|
||||
}
|
||||
$frag = [];
|
||||
$article_info = $this->article_obj->where("article_id",$data['article_id'])->find();
|
||||
if($article_info['is_buy']==1){
|
||||
return jsonError("paid");
|
||||
@@ -56,34 +64,88 @@ class Order extends base{
|
||||
$journal_info = $this->journal_obj->where("journal_id",$article_info['journal_id'])->find();
|
||||
$check = $this->order_obj->where("user_id",$article_info['user_id'])->where("article_id",$data['article_id'])->whereIn("state",[0,1])->find();
|
||||
if($check){
|
||||
$re['detail'] = $check;
|
||||
$ii = $this->createPaypalOrder($check['real_fee']);
|
||||
if(!isset($ii['jsonResponse']['status'])||$ii['jsonResponse']['status']!="CREATED"){
|
||||
return jsonError("system error!");
|
||||
if($payType==0){
|
||||
$ii = $this->createPaypalOrder($check['real_fee']);
|
||||
// if(!isset($ii['jsonResponse']['status'])||$ii['jsonResponse']['status']!="CREATED"){
|
||||
if(!isset($ii['jsonResponse']['status'])){
|
||||
return jsonError("system error!");
|
||||
}else{
|
||||
$check['paypal_order_id'] = $ii['jsonResponse']['id'];
|
||||
}
|
||||
$check['pay_type'] = 0;
|
||||
$this->order_obj->update($check);
|
||||
$re['detail'] = $check;
|
||||
$re['paypal'] = $ii;
|
||||
$re['paystation'] = null;
|
||||
return jsonSuccess($re);
|
||||
}else{
|
||||
$check['paypal_order_id'] = $ii['jsonResponse']['id'];
|
||||
$cache_sn = 'TMR'.date('Ymd') . strtoupper(bin2hex(random_bytes(8)));
|
||||
$accessToken = createPayStationToken();
|
||||
$data_array = [
|
||||
'paystation_id' => Env::get("paystation.client_id"),
|
||||
'gateway_id' => "PAYSTATION",//GATEWAY_ID,
|
||||
"order_name" => $cache_sn,
|
||||
"amount" =>100,
|
||||
"test_mode"=>true
|
||||
];
|
||||
$data = json_encode($data_array);
|
||||
$purchase = postPayStationQuery('v1/payme/purchases', $accessToken, $data);
|
||||
$paystation_res = object_to_array(json_decode($purchase));
|
||||
$check['pay_type'] = 2;
|
||||
$check['paystation_url'] = $paystation_res['payme_url'];
|
||||
$this->order_obj->update($check);
|
||||
$re['detail'] = $check;
|
||||
$re['paypal'] = null;
|
||||
$re['paystation'] = $paystation_res;
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
$this->order_obj->update($check);
|
||||
$re['paypal'] = $ii;
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
$insert['order_sn'] = 'TMR'.date('Ymd') . strtoupper(bin2hex(random_bytes(8)));
|
||||
$insert['user_id'] = $article_info['user_id'];
|
||||
$insert['type'] = 0;
|
||||
$insert["article_id"] = $data['article_id'];
|
||||
$insert['order_fee'] = $journal_info['fee'];
|
||||
$insert['real_fee'] = $journal_info['fee'];
|
||||
$paypal = $this->createPaypalOrder($insert['real_fee']);
|
||||
if(!isset($paypal['jsonResponse']['status'])||$paypal['jsonResponse']['status']!="CREATED"){
|
||||
return jsonError("system error");
|
||||
}else{
|
||||
$insert['paypal_order_id'] = $paypal['jsonResponse']['id'];
|
||||
|
||||
if($payType==0){//支付方式为paypal
|
||||
$insert['order_sn'] = 'TMR'.date('Ymd') . strtoupper(bin2hex(random_bytes(8)));
|
||||
$insert['user_id'] = $article_info['user_id'];
|
||||
$insert['type'] = 0;
|
||||
$insert["article_id"] = $data['article_id'];
|
||||
$insert['order_fee'] = $journal_info['fee'];
|
||||
$insert['real_fee'] = $journal_info['fee'];
|
||||
$frag["paypal"] = $this->createPaypalOrder($insert['real_fee']);
|
||||
if(!isset($paypal['jsonResponse']['status'])||$paypal['jsonResponse']['status']!="CREATED"){
|
||||
return jsonError("system error");
|
||||
}else{
|
||||
$insert['paypal_order_id'] = $paypal['jsonResponse']['id'];
|
||||
}
|
||||
$insert['ctime'] = time();
|
||||
$id = $this->order_obj->insertGetId($insert);
|
||||
$frag['paystation'] = null;
|
||||
}elseif ($payType==2){//支付方式为paystation
|
||||
$ca_sn = 'TMR'.date('Ymd') . strtoupper(bin2hex(random_bytes(8)));
|
||||
$insert['order_sn'] = $ca_sn;
|
||||
$insert['user_id'] = $article_info['user_id'];
|
||||
$insert['type'] = 2;
|
||||
$insert["article_id"] = $data['article_id'];
|
||||
$insert['order_fee'] = $journal_info['fee'];
|
||||
$insert['real_fee'] = $journal_info['fee'];
|
||||
$accessToken = createPayStationToken();
|
||||
$data_array = [
|
||||
'paystation_id' => Env::get("paystation.client_id"),
|
||||
'gateway_id' => "PAYSTATION",//GATEWAY_ID,
|
||||
"order_name" => $ca_sn,
|
||||
"amount" =>100,
|
||||
"test_mode"=>true
|
||||
];
|
||||
$data = json_encode($data_array);
|
||||
$purchase = postPayStationQuery('v1/payme/purchases', $accessToken, $data);
|
||||
$paystation_res = object_to_array(json_decode($purchase));
|
||||
$insert['paystation_url'] = $paystation_res['payme_url'];
|
||||
$insert['ctime'] = time();
|
||||
$id = $this->order_obj->insertGetId($insert);
|
||||
$frag['paystation'] = $paystation_res;
|
||||
$frag["paypal"] = null;
|
||||
}else{//暂时不处理,其他情况
|
||||
return jsonError("pay_type error");
|
||||
}
|
||||
$insert['ctime'] = time();
|
||||
$id = $this->order_obj->insertGetId($insert);
|
||||
$re['detail'] = $this->order_obj->where("order_id",$id)->find();
|
||||
$re['paypal'] = $paypal;
|
||||
return jsonSuccess($re);
|
||||
$frag['detail'] = $this->order_obj->where("order_id",$id)->find();
|
||||
return jsonSuccess($frag);
|
||||
}
|
||||
|
||||
|
||||
@@ -150,12 +212,15 @@ class Order extends base{
|
||||
PurchaseUnitRequestBuilder::init(
|
||||
AmountWithBreakdownBuilder::init("USD", $fee)->build()
|
||||
)->build(),
|
||||
// PaymentSourceBuilder::init()->paypal(PaypalWalletBuilder::init()->experienceContext(
|
||||
// PaypalWalletExperienceContextBuilder::init()->returnUrl("https://www.baidu.com")->build()
|
||||
// )->build())->build(),
|
||||
])->applicationContext(
|
||||
OrderApplicationContextBuilder::init()->returnUrl("www.baidu.com")->build()
|
||||
)->build(),
|
||||
])
|
||||
->paymentSource(
|
||||
PaymentSourceBuilder::init()->paypal(
|
||||
PaypalWalletBuilder::init()->experienceContext(
|
||||
PaypalWalletExperienceContextBuilder::init()->returnUrl("https://www.baidu.com")->build()
|
||||
)->build()
|
||||
)->build()
|
||||
)
|
||||
->build(),
|
||||
];
|
||||
$apiResponse = $client->getOrdersController()->ordersCreate($orderBody);
|
||||
|
||||
|
||||
@@ -1130,7 +1130,7 @@ class Preaccept extends Base
|
||||
$accessToken = $this->payStationAccessToken();
|
||||
$data_array = [
|
||||
'paystation_id' => Env::get("paystation.client_id"),
|
||||
'gateway_id' => "v1",//GATEWAY_ID,
|
||||
'gateway_id' => "PAYSTATION",//GATEWAY_ID,
|
||||
'merchant_session' => "myTestSN001",
|
||||
// 'merchant_reference' => 'testReference',
|
||||
'amount' => 2000, //$20 in cents value
|
||||
@@ -1165,35 +1165,15 @@ class Preaccept extends Base
|
||||
$accessToken = $this->payStationAccessToken();
|
||||
$data_array = [
|
||||
'paystation_id' => Env::get("paystation.client_id"),
|
||||
'gateway_id' => "v1",//GATEWAY_ID,
|
||||
"order_name" => "mytestOrderSn",
|
||||
"amount" =>200,
|
||||
'gateway_id' => "PAYSTATION",//GATEWAY_ID,
|
||||
"order_name" => "mytestOrderSn11",
|
||||
"amount" =>100,
|
||||
"test_mode"=>true
|
||||
];
|
||||
$data = json_encode($data_array);
|
||||
|
||||
$purchase = $this->postRequest('v1/payme/purchases', $accessToken, $data);
|
||||
|
||||
return jsonSuccess($purchase);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function patStationReturn(){
|
||||
$query_string = $_SERVER['QUERY_STRING'];
|
||||
parse_str($query_string, $data);
|
||||
|
||||
if (isset($data['code'])) {
|
||||
// Add code here to display result
|
||||
// Do not update transaction status here because query strings can be manipulated
|
||||
// Do a transaction lookup instead to verify the results. Check documentation for more details.
|
||||
if ($data['code'] == '0') {
|
||||
echo 'Transaction ok: ' . $data['message'];
|
||||
} else {
|
||||
echo 'Transaction failed: ' . $data['message'];
|
||||
}
|
||||
}
|
||||
$r= object_to_array(json_decode($purchase));
|
||||
return jsonSuccess($r);
|
||||
}
|
||||
|
||||
private function payStationAccessToken(){
|
||||
@@ -1201,7 +1181,7 @@ class Preaccept extends Base
|
||||
'client_id' => Env::get("paystation.client_id"),
|
||||
'client_secret' => Env::get("paystation.client_secret"),
|
||||
'grant_type' => 'client_credentials',
|
||||
'scope' => "mytest"
|
||||
'scope' => "read write"
|
||||
];
|
||||
$accessTokenUrl = Env::get("paystation.api_url") . '/oauth/token';
|
||||
$curlHandle = curl_init($accessTokenUrl);
|
||||
|
||||
Reference in New Issue
Block a user