Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetaGer Keymanager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
MetaGer Keymanager
Commits
57244346
Commit
57244346
authored
2 years ago
by
Dominik Hebeler
Browse files
Options
Downloads
Patches
Plain Diff
fixed card payments
parent
24305f82
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pass/app/payment_processor/Paypal.js
+18
-0
18 additions, 0 deletions
pass/app/payment_processor/Paypal.js
pass/routes/checkout/paypal.js
+15
-24
15 additions, 24 deletions
pass/routes/checkout/paypal.js
with
33 additions
and
24 deletions
pass/app/payment_processor/Paypal.js
+
18
−
0
View file @
57244346
...
@@ -293,6 +293,24 @@ class Paypal extends PaymentProcessor {
...
@@ -293,6 +293,24 @@ class Paypal extends PaymentProcessor {
});
});
}
}
// Client Token for handling credit card payments
async
generateClientToken
()
{
const
accessToken
=
await
this
.
#generateAccessToken
();
const
response
=
await
fetch
(
`
${
base
}
/v1/identity/generate-token`
,
{
method
:
"
post
"
,
headers
:
{
Authorization
:
`Bearer
${
accessToken
}
`
,
"
Accept-Language
"
:
"
en_US
"
,
"
Content-Type
"
:
"
application/json
"
,
},
});
const
data
=
await
response
.
json
();
return
data
.
client_token
;
}
/**
/**
* Turns class object into serializable data to store in redis db
* Turns class object into serializable data to store in redis db
*
*
...
...
This diff is collapsed.
Click to expand it.
pass/routes/checkout/paypal.js
+
15
−
24
View file @
57244346
...
@@ -31,7 +31,7 @@ router.get("/:funding_source", async (req, res) => {
...
@@ -31,7 +31,7 @@ router.get("/:funding_source", async (req, res) => {
res
.
header
({
"
Access-Control-Allow-Origin
"
:
"
https://www.paypal.com
"
});
res
.
header
({
"
Access-Control-Allow-Origin
"
:
"
https://www.paypal.com
"
});
if
(
req
.
params
.
funding_source
===
"
card
"
)
{
if
(
req
.
params
.
funding_source
===
"
card
"
)
{
let
client_token
=
await
generateClientToken
();
let
client_token
=
await
new
Paypal
().
generateClientToken
();
req
.
data
.
checkout
.
payment
.
paypal
.
client_token
=
client_token
;
req
.
data
.
checkout
.
payment
.
paypal
.
client_token
=
client_token
;
}
}
...
@@ -119,18 +119,20 @@ router.post("/:funding_source/order/cancel", async (req, res) => {
...
@@ -119,18 +119,20 @@ router.post("/:funding_source/order/cancel", async (req, res) => {
router
.
use
(
"
/card/order/capture
"
,
async
(
req
,
res
,
next
)
=>
{
router
.
use
(
"
/card/order/capture
"
,
async
(
req
,
res
,
next
)
=>
{
console
.
debug
(
req
.
body
.
order_id
);
console
.
debug
(
req
.
body
.
order_id
);
Order
.
LOAD_ORDER_FROM_ID
(
req
.
body
.
order_id
)
Order
.
LOAD_ORDER_FROM_ID
(
req
.
body
.
order_id
)
.
then
((
order
)
=>
loaded_
order
.
getPaymentProcessor
().
verify3D
())
.
then
((
order
)
=>
order
.
getPaymentProcessor
().
verify
_
3D
())
.
then
(()
=>
next
(
"
route
"
))
.
then
(()
=>
next
(
"
route
"
))
.
catch
((
reason
)
=>
{
.
catch
((
reason
)
=>
{
console
.
debug
(
reason
);
console
.
debug
(
reason
);
res
.
status
(
400
).
json
({
msg
:
"
3D Verification Failed
"
});
res
.
status
(
400
).
json
({
errors
:
[
{
type
:
"
PAYPAL_CARD_3D_ERROR
"
,
msg
:
"
3D Verification Failed
"
},
],
});
});
});
});
});
// capture payment & store order information or fullfill order
// capture payment & store order information or fullfill order
router
.
post
(
"
/:funding_source/order/capture
"
,
async
(
req
,
res
)
=>
{
router
.
post
(
"
/:funding_source/order/capture
"
,
async
(
req
,
res
)
=>
{
//res.status(200).json({ test: "test" });
//return;
Order
.
LOAD_ORDER_FROM_ID
(
req
.
body
.
order_id
).
then
(
Order
.
LOAD_ORDER_FROM_ID
(
req
.
body
.
order_id
).
then
(
/**
/**
* @param {Order} loaded_order
* @param {Order} loaded_order
...
@@ -155,7 +157,14 @@ router.post("/:funding_source/order/capture", async (req, res) => {
...
@@ -155,7 +157,14 @@ router.post("/:funding_source/order/capture", async (req, res) => {
console
.
debug
(
reason
);
console
.
debug
(
reason
);
res
res
.
status
(
400
)
.
status
(
400
)
.
json
({
errors
:
[{
msg
:
"
Couldn't capture the payment
"
}]
});
.
json
({
errors
:
[
{
type
:
"
PAYMENT_NOT_COMPLETED_ERROR
"
,
msg
:
"
Couldn't capture the payment
"
,
},
],
});
});
});
}
}
);
);
...
@@ -339,22 +348,4 @@ async function refundPayment(capture_ids) {
...
@@ -339,22 +348,4 @@ async function refundPayment(capture_ids) {
return
Promise
.
all
(
promises
);
return
Promise
.
all
(
promises
);
}
}
// Client Token for handling credit card payments
async
function
generateClientToken
()
{
const
accessToken
=
await
generateAccessToken
();
const
response
=
await
fetch
(
`
${
base
}
/v1/identity/generate-token`
,
{
method
:
"
post
"
,
headers
:
{
Authorization
:
`Bearer
${
accessToken
}
`
,
"
Accept-Language
"
:
"
en_US
"
,
"
Content-Type
"
:
"
application/json
"
,
},
});
const
data
=
await
response
.
json
();
return
data
.
client_token
;
}
// generate an access token using client id and app secret
// generate an access token using client id and app secret
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment