sequenceDiagram
participant Frontend
participant PayU
actor User
participant Plugin
Frontend ->> PayU: PaymentLink is requested
User ->> PayU: Authorization
PayU ->> Plugin: PENDING status webhook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id":46, | |
"customerIp":"127.0.0.1", | |
"description":"test", | |
"currencyCode":"PLN", | |
"totalAmount":"1000", | |
"buyer":null, | |
"products":null, | |
"status":"PENDING", | |
"redirectUri":"https://merch-prod.snd.payu.com/pay/?orderId=TFJBNPX6ZS220409GUEST000P01&token=eyJhbGciOiJIUzI1NiJ9.eyJvcmRlcklkIjoiVEZKQk5QWDZaUzIyMDQwOUdVRVNUMDAwUDAxIiwicG9zSWQiOiJvZzVIeTU5ZSIsImF1dGhvcml0aWVzIjpbIlJPTEVfQ0xJRU5UIl0sImV4cCI6MTY0OTU4MjQ1OSwiaXNzIjoiUEFZVSIsImF1ZCI6ImFwaS1nYXRld2F5Iiwic3ViIjoiUGF5VSBzdWJqZWN0IiwianRpIjoiNWZhYjVmYTAtNzA5Mi00NDdkLTlmOGEtZTUzMGM0NjlmZjQ4In0.d2MrRjcOTWF_H5DvQJbzBcnI8-hbi8VZ6NN1AdF3JP0", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
async handleWebhook(data) { | |
const { configuration, settings } = await strapi | |
.plugin('payu') | |
.service('settings') | |
.getSettings(); | |
const { token } = await strapi | |
.plugin('payu') | |
.service('auth') | |
.getToken(settings); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"transaction": { | |
"id":23, | |
"uid":"24c6d9b2-c707-4d2a-8887-3991b903b3f6", | |
"customerIp":"127.0.0.1", | |
"description":"test", | |
"currencyCode":"PLN", | |
"totalAmount":"1000", | |
"buyer":null, | |
"products":null, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"order": { | |
"orderId": "TFJBNPX6ZS220409GUEST000P01", | |
"extOrderId": "24c6d9b2-c707-4d2a-8887-3991b903b3f6", | |
"orderCreateDate": "2022-04-09T11:20:59.521+02:00", | |
"notifyUrl": "https://webhook.site/5e25fb1d-a0cb-47ef-b8f7-f71ca7f7d5cc", | |
"customerIp": "127.0.0.1", | |
"merchantPosId": "300746", | |
"validityTime": "86400", | |
"description": "test", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"order": { | |
"orderId": "TFJBNPX6ZS220409GUEST000P01", | |
"extOrderId": "24c6d9b2-c707-4d2a-8887-3991b903b3f6", | |
"orderCreateDate": "2022-04-09T11:20:59.521+02:00", | |
"notifyUrl": "https://webhook.site/5e25fb1d-a0cb-47ef-b8f7-f71ca7f7d5cc", | |
"customerIp": "127.0.0.1", | |
"merchantPosId": "300746", | |
"validityTime": "86400", | |
"description": "test", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server/routes/index.js | |
module.exports = [ | |
{ | |
method: 'POST', | |
path: '/transactions', | |
handler: 'paymentLink.createTransaction', | |
config: { | |
auth: false, | |
policies: [], | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server/controllers/payment-link.js | |
'use strict' | |
module.exports = { | |
async createTransaction(ctx) { | |
ctx.body = await strapi | |
.plugin('payu') | |
.service('paymentLink') | |
.createTransaction(ctx.request.body) | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server/services/payment-link.js | |
'use strict' | |
const { v4: uuid } = require('uuid') | |
const { createOrder } = require('../utils/payu') | |
module.exports = ({ strapi }) => ({ | |
async createTransaction(data) { | |
const { configuration, settings } = await strapi | |
.plugin('payu') | |
.service('settings') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
createOrder: async function(settings, token, transaction) { | |
const { payuApiUrl, merchantPosId, notifyUrl } = settings | |
const validityTime = 24 * 60 * 60 | |
const headers = { | |
'Content-Type': 'application/json', | |
'Authorization': 'Bearer ' + token | |
} | |
const options = { headers, "maxRedirects": 0 } | |
const { |