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/content-types/sandbox-settings.js | |
module.exports = { | |
schema: { | |
kind: "singleType", | |
collectionName: "sandbox_settings", | |
info: { | |
singularName: "sandbox-settings", | |
pluralName: "sandbox-settings", | |
displayName: "PayU Settings - Sandbox", | |
description: "" |
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/content-types/configuration.js | |
module.exports = { | |
schema: { | |
kind: "singleType", | |
collectionName: "configuration", | |
info: { | |
singularName: "configuration", | |
pluralName: "configurations", | |
displayName: "PayU Configuration", | |
description: "" |
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/bootstrap.js | |
'use strict'; | |
module.exports = async ({ strapi }) => { | |
// bootstrap phase | |
const configurationCollection = await strapi | |
.query('plugin::payu.configuration') | |
const configuration = await configurationCollection | |
.findOne(); | |
if (!configuration) { | |
strapi.log.info("Create default PayU configuration"); |
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/utils/payu.js | |
'use strict'; | |
const axios = require("axios") | |
module.exports = { | |
getToken: async function(settings) { | |
const { payuAuthorizeUrl, clientId, clientSecret } = settings | |
const params = new URLSearchParams() | |
params.append("grant_type", "client_credentials") | |
params.append("client_id", clientId) | |
params.append("client_secret", clientSecret) |
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
'use strict'; | |
const payu = require("../utils/payu"); | |
module.exports = ({ strapi }) => ({ | |
getWelcomeMessage() { | |
return 'Welcome to Strapi 🚀'; | |
}, | |
async getToken() { | |
// Collect settings from database | |
let config = await strapi | |
.query('plugin::payu.conguration') |
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/settings.js | |
'use strict'; | |
const payu = require("../utils/payu"); | |
module.exports = ({ strapi }) => ({ | |
async getSettings() { | |
// Collect settings from database | |
const configuration = await strapi | |
.query('plugin::payu.configuration') | |
.findOne(); |
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/auth.js | |
'use strict'; | |
const payu = require("../utils/payu"); | |
module.exports = ({ strapi }) => ({ | |
async getToken() { | |
const { settings } = await strapi | |
.plugin('payu') | |
.service('settings') | |
.getSettings(); | |
const token = await payu.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
// server/content-types/transactions.js | |
module.exports = { | |
schema: { | |
kind: "collectionType", | |
collectionName: "transactions", | |
info: { | |
singularName: "transaction", | |
pluralName: "transactions", | |
displayName: "PayU Transactions", | |
description: "" |
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 { |
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') |