|
@@ -90,8 +90,8 @@ class PayPal
|
|
|
{
|
|
|
$apiContext = new ApiContext(
|
|
|
new OAuthTokenCredential(
|
|
|
- 'AS0FH780ZGtSAdpT1NTjwkFzryCPf69rZb_FR9Rt_rZdasB80cmjqTQ6CQELWiFVh_MU9e31CSnyz7Ai', // ClientID
|
|
|
- 'EDqRQhgLNHCb5bxld98T8-JJJZKvMIeqxudO7lMwDFOxBfy138PjM5A21FnDNyb3q4yYUh8r7Qr2BnVi' // ClientSecret
|
|
|
+ $this->config['client_id'], // ClientID
|
|
|
+ $this->config['secret'] // ClientSecret
|
|
|
)
|
|
|
);
|
|
|
|
|
@@ -107,8 +107,15 @@ class PayPal
|
|
|
$transaction->setAmount($amount);
|
|
|
|
|
|
$redirectUrls = new RedirectUrls();
|
|
|
- $redirectUrls->setReturnUrl("https://lar.lmm.gold/api/index/index")
|
|
|
- ->setCancelUrl("https://lar.lmm.gold/store/index.html");
|
|
|
+ //live
|
|
|
+ //$return_url = config('app.app_host') . $this->config['return_url'] . $outTradeNo;
|
|
|
+ //$cancel_Url = config('app.app_host').$this->config['cancel_url'];
|
|
|
+ //sandbox
|
|
|
+ $return_url = 'https://lar.lmm.gold/api/index/index';
|
|
|
+ $cancel_url = 'https://lar.lmm.gold/store/index.html';
|
|
|
+
|
|
|
+ $redirectUrls->setReturnUrl($return_url)
|
|
|
+ ->setCancelUrl($cancel_url);
|
|
|
|
|
|
$payment = new Payment();
|
|
|
$payment->setIntent('sale')
|
|
@@ -116,21 +123,10 @@ class PayPal
|
|
|
->setTransactions(array($transaction))
|
|
|
->setRedirectUrls($redirectUrls);
|
|
|
|
|
|
- //$payment->create($apiContext);
|
|
|
-
|
|
|
-
|
|
|
- $this->result = $payment->create($apiContext);// This will print the detailed information on the exception.
|
|
|
- //REALLY HELPFUL FOR DEBUGGING
|
|
|
-// $this->throwError('支付宝API交易查询失败:' . , true, 'tradeQuery');
|
|
|
-// return false;
|
|
|
- echo $this->result;die;
|
|
|
- echo "\n\nRedirect user to approval_url: " . $payment->getApprovalLink() . "\n";
|
|
|
- // 记录日志
|
|
|
- Log::append('PayPal-unify', ['result' => $this->result]);
|
|
|
- return ['approval_link'=>$payment->getApprovalLink()];
|
|
|
- redirect($payment->getApprovalLink());
|
|
|
- // 请求成功
|
|
|
- return true;
|
|
|
+ $this->result = $payment->create($apiContext);// This will print the detailed information on the exception.
|
|
|
+ //REALLY HELPFUL FOR DEBUGGING
|
|
|
+ //echo "\n\nRedirect user to approval_url: " . $payment->getApprovalLink() . "\n";
|
|
|
+ return ['approval_link' => $payment->getApprovalLink()];
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -143,7 +139,7 @@ class PayPal
|
|
|
{
|
|
|
try {
|
|
|
|
|
|
- $result = Order::get($outTradeNo, $this->apiContext);
|
|
|
+ $payment = Payment::get($outTradeNo, $this->apiContext);
|
|
|
// 记录日志
|
|
|
Log::append('Paypal-tradeQuery', ['outTradeNo' => $outTradeNo, 'result' => json_encode($result)]);
|
|
|
// 处理响应或异常
|
|
@@ -165,7 +161,14 @@ class PayPal
|
|
|
|
|
|
// 执行付款
|
|
|
$payment->execute($execution, $this->apiContext);
|
|
|
- return $payment::get($payment->getId(), $this->apiContext);
|
|
|
+ $payment::get($payment->getId(), $this->apiContext);
|
|
|
+ $transactions = $payment->getTransactions();
|
|
|
+ \think\facade\Log::error('$transactions::' . json_encode($transactions));
|
|
|
+ if ($payment->getState() == 'approved' && $payment->getId() == $paymentId) {
|
|
|
+ //related_resources->sale->id
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
\think\facade\Log::error('executePayment', ['paymentId' => $paymentId, 'errMsg' => $e->getMessage()]);
|
|
@@ -213,16 +216,6 @@ class PayPal
|
|
|
\think\facade\Log::error('PayPal Notification Verify Failed' . $exception->getMessage());
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
- // 记录日志
|
|
|
-// Log::append('PayPal-notify', [
|
|
|
-// 'params' => $this->notifyParams,
|
|
|
-// 'verifyNotify' => $verifyNotify,
|
|
|
-// 'response' => $this->getNotifyResponse(),
|
|
|
-// 'result' => $this->notifyResult,
|
|
|
-// 'message' => '支付宝异步回调验证' . ($this->notifyResult ? '成功' : '失败')
|
|
|
-// ]);
|
|
|
- return $this->notifyResult;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -255,7 +248,6 @@ class PayPal
|
|
|
*/
|
|
|
public function transfers(string $outTradeNo, string $totalFee, array $extra = []): bool
|
|
|
{
|
|
|
- // https://opendocs.alipay.com/apis/api_28/alipay.fund.trans.uni.transfer
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -299,8 +291,6 @@ class PayPal
|
|
|
*/
|
|
|
public function setOptions(array $options, string $client)
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
@@ -326,28 +316,12 @@ class PayPal
|
|
|
*/
|
|
|
private function extraAsUnify(array $extra): array
|
|
|
{
|
|
|
- if ($this->client === ClientEnum::H5) {
|
|
|
- if (!array_key_exists('returnUrl', $extra)) {
|
|
|
- $this->throwError('returnUrl参数不存在');
|
|
|
- }
|
|
|
+ if (!array_key_exists('returnUrl', $extra)) {
|
|
|
+ $this->throwError('returnUrl参数不存在');
|
|
|
}
|
|
|
return $extra;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 删除HTML中的指定标签
|
|
|
- * @param array $tags
|
|
|
- * @param $string
|
|
|
- * @return array|string|string[]|null
|
|
|
- */
|
|
|
- private function deleteHtmlTags(array $tags, $string)
|
|
|
- {
|
|
|
- $preg = [];
|
|
|
- foreach ($tags as $key => $value) {
|
|
|
- $preg[$key] = "/<({$value}.*?)>(.*?)<(\/{$value}.*?)>/si";
|
|
|
- }
|
|
|
- return preg_replace($preg, '', $string);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 异步回调地址
|