Skip to content

Commit 57f8748

Browse files
committed
add google pay
1 parent 88bee3e commit 57f8748

11 files changed

+701
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.vercel
2+
node_modules/
3+
4+
.env

api/confirm-payment.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import axios from 'axios'
2+
3+
export default async (req, res) => {
4+
const data = {
5+
paymentSessionId: req.requestId,
6+
state: 'processed',
7+
transactionId: req.requestId,
8+
instructions: 'Your payment will appear on your statement in the coming days',
9+
}
10+
11+
const options = {
12+
headers: {
13+
Authorization: `Bearer ${process.env.SNIP_PAYMENT_API_KEY}`
14+
}
15+
}
16+
17+
try{
18+
const resp = await axios.post(`${process.env.PAYMENT_URL}/api/private/custom-payment-gateway/payment`,data, options)
19+
return res.json({
20+
returnUrl: resp.data.returnUrl
21+
})
22+
}catch(e){
23+
console.error(e)
24+
}
25+
26+
return res.status(500).send()
27+
}

api/payment-methods.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import axios from 'axios'
2+
3+
export default async (req, res) => {
4+
if (req.body && req.body.publicToken) {
5+
console.log(req.body.publicToken)
6+
try {
7+
await axios.get(`${process.env.PAYMENT_URL}/api/public/custom-payment-gateway/validate?publicToken=${req.body.publicToken}`)
8+
return res.json([{
9+
id: 'paymentrequest-custom-gateway',
10+
name: 'Google pay',
11+
checkoutUrl: 'https://paymentrequest-custom-gateway-bpd1p4ouk.vercel.app'
12+
}])
13+
}catch(e){
14+
console.error(e)
15+
}
16+
}
17+
return res.status(500).send()
18+
}

package-lock.json

+170
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "paymentrequest-custom-gateway",
3+
"version": "1.0.0",
4+
"description": "Snipcart Custom Payment Gateway implementation using Payment Request API",
5+
"main": "index.js",
6+
"scripts": {
7+
"deploy": "npx vercel deploy",
8+
"start": "npx vercel dev",
9+
"tunnel": "npx ngrok http 3000 --subdomain=custompayment"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/snipcart/paymentrequest-custom-gateway.git"
14+
},
15+
"author": "",
16+
"license": "ISC",
17+
"bugs": {
18+
"url": "https://github.com/snipcart/paymentrequest-custom-gateway/issues"
19+
},
20+
"homepage": "https://github.com/snipcart/paymentrequest-custom-gateway#readme",
21+
"dependencies": {
22+
"axios": "^0.19.2"
23+
},
24+
"devDependencies": {
25+
"vercel": "^19.1.1"
26+
}
27+
}

src/index.html

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Custom payment gateway | payment request api</title>
7+
<script src="./index.js"></script>
8+
<link rel="stylesheet" href="./styles.css">
9+
</link>
10+
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
11+
</head>
12+
13+
<body>
14+
<div class="container">
15+
<div class="header">
16+
<svg xmlns="http://www.w3.org/2000/svg" width="207" height="207" viewBox="0 0 207 207" class="header__logo">
17+
<path id="Union_1" data-name="Union 1"
18+
d="M114.971,164.689c-1.409-5.349-6.215-13.627-22.52-12.471A76.907,76.907,0,0,1,.5,77.1,76.819,76.819,0,1,1,153.293,88.5c-1.615,20.975,9.865,25.913,13.6,26.959a46.206,46.206,0,1,1-51.926,49.23Z"
19+
transform="translate(-0.5 -0.5)" fill="#429bfc"></path>
20+
</svg>
21+
<h1>Replica zone</h1>
22+
</div>
23+
<div class="divider"></div>
24+
<table>
25+
<tbody>
26+
</tbody>
27+
<tfoot>
28+
</tfoot>
29+
</table>
30+
<div class="divider"></div>
31+
<button class="center" id="pay">Pay now</button>
32+
</div>
33+
</body>
34+
35+
</html>

0 commit comments

Comments
 (0)