Toggle navigation
Toggle navigation
This project
Loading...
Sign in
OnePoem
/
OnePoem-Server
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
李帅
2022-05-31 23:23:32 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e531f5c2d2c8857e287763d2e6f1876282a24c0b
e531f5c2
1 parent
df9502b1
1.打印paypal token
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
24 deletions
app/Payment/PaypalPayment.php
app/Payment/PaypalPayment.php
View file @
e531f5c
...
...
@@ -14,6 +14,7 @@ use App\Models\User;
use
App\Models\UserProfile
;
use
Carbon\Carbon
;
use
GuzzleHttp\Client
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\Facades\Redis
;
class
PaypalPayment
implements
PaymentInterface
...
...
@@ -34,29 +35,32 @@ class PaypalPayment implements PaymentInterface
public
function
__construct
()
{
// 初始化时做一些准备工作
$redis
=
Redis
::
connection
();
$access_token
=
$redis
->
get
(
'paypal:access_token'
);
if
(
$access_token
){
$this
->
accessToken
=
$access_token
;
}
else
{
$client
=
new
Client
([
'base_uri'
=>
$this
->
baseUrlSandbox
,
'headers'
=>
[
'Content-Type'
=>
'application/x-www-form-urlencoded'
,
'Accept'
=>
'application/json'
,
]
]);
$response
=
$client
->
post
(
'/v1/oauth2/token'
,[
'form_params'
=>
[
'grant_type'
=>
'client_credentials'
],
'auth'
=>
[
$this
->
clientId
,
$this
->
secret
],
]);
$body
=
$response
->
getBody
();
$content
=
json_decode
(
$body
->
getContents
(),
true
);
$this
->
accessToken
=
$content
[
'access_token'
];
$redis
->
setex
(
'paypal:access_token'
,
$content
[
'expires_in'
],
$content
[
'access_token'
]);
try
{
// 初始化时做一些准备工作
$redis
=
Redis
::
connection
();
$access_token
=
$redis
->
get
(
'paypal:access_token'
);
if
(
$access_token
){
$this
->
accessToken
=
$access_token
;
}
else
{
$client
=
new
Client
([
'base_uri'
=>
$this
->
baseUrlSandbox
,
'headers'
=>
[
'Content-Type'
=>
'application/x-www-form-urlencoded'
,
'Accept'
=>
'application/json'
,
]
]);
$response
=
$client
->
post
(
'/v1/oauth2/token'
,[
'form_params'
=>
[
'grant_type'
=>
'client_credentials'
],
'auth'
=>
[
$this
->
clientId
,
$this
->
secret
],
]);
$body
=
$response
->
getBody
();
$content
=
json_decode
(
$body
->
getContents
(),
true
);
$this
->
accessToken
=
$content
[
'access_token'
];
$redis
->
setex
(
'paypal:access_token'
,
$content
[
'expires_in'
],
$content
[
'access_token'
]);
}
}
catch
(
\Exception
$exception
){
Log
::
channel
(
'daily'
)
->
error
(
$exception
->
getMessage
());
}
}
...
...
@@ -98,7 +102,7 @@ class PaypalPayment implements PaymentInterface
}
public
function
prepare
(
Order
$order
)
{
return
$this
->
accessToken
;
{
// 在PayPal上创建一个订单,它会返回一个订单对象,它有一个订单id
$client
=
new
Client
([
'base_uri'
=>
$this
->
baseUrlSandbox
,
...
...
Please
register
or
login
to post a comment