Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
include oneclickpayment
Browse files Browse the repository at this point in the history
  • Loading branch information
janfabian committed Apr 6, 2020
1 parent cd74add commit a3fd374
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 11 deletions.
105 changes: 105 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,111 @@ const csob = ({
return body;
},

status: async (payId) => {
const payloadData = payload.status({
merchantId,
payId,
});

const signature = util.objectToStringWithOrder({
obj: payloadData,
order: payload.order.status,
optional: payload.optional.status,
});

payloadData.signature = await crypto.sign(signature, privateKey);

const { body } = await request
.post(`${config.uri}/${config.methods.status}`)
.send(payload);

crypto.verifyResponse(body, true, {
csobPublicKey: config.csobPublicKey,
optional: payload.optional.response,
order: payload.order.response,
});

return body;
},

oneclick: {
init: async (data) => {
const payloadData = payload.oneclick.init({
merchantId,
...data,
});
const signature = util.objectToStringWithOrder({
obj: payloadData,
order: payload.order.oneclick.init,
optional: payload.optional.oneclick.init,
});
payloadData.signature = await crypto.sign(signature, privateKey);
const { body } = await request
.post(`${config.uri}/${config.methods.oneclick.init}`)
.send(payloadData);

crypto.verifyResponse(body, true, {
csobPublicKey: config.csobPublicKey,
optional: payload.optional.response,
order: payload.order.response,
});

return body;
},
start: async (payId) => {
const payloadData = payload.oneclick.start({
merchantId,
payId,
});

const signature = util.objectToStringWithOrder({
obj: payloadData,
order: payload.order.oneclick.start,
optional: payload.optional.oneclick.start,
});

payloadData.signature = await crypto.sign(signature, privateKey);

const { body } = await request
.post(`${config.uri}/${config.methods.oneclick.start}`)
.send(payloadData);

crypto.verifyResponse(body, true, {
csobPublicKey: config.csobPublicKey,
optional: payload.optional.response,
order: payload.order.response,
});

return body;
},
echo: async (payId) => {
const payloadData = payload.oneclick.echo({
merchantId,
origPayId: payId,
});

const signature = util.objectToStringWithOrder({
obj: payloadData,
order: payload.order.oneclick.echo,
optional: payload.optional.oneclick.echo,
});

payloadData.signature = await crypto.sign(signature, privateKey);

const { body } = await request
.post(`${config.uri}/${config.methods.oneclick.echo}`)
.send(payloadData);

crypto.verifyResponse(body, true, {
csobPublicKey: config.csobPublicKey,
optional: payload.optional.response,
order: payload.order.response,
});

return body;
},
},

verifyCsobRequest: (body) => {
return crypto.verifyResponse(body, true, {
csobPublicKey: config.csobPublicKey,
Expand Down
5 changes: 3 additions & 2 deletions payment/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ const config = {
status: "payment/status",
reverse: "payment/reverse",
oneclick: {
init: "payment/oneclick/init",
start: "payment/oneclick/start",
echo: "oneclick/echo",
init: "oneclick/init",
start: "oneclick/start",
},
},
};
Expand Down
21 changes: 12 additions & 9 deletions payment/payload/v1.8.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
returnUrl,
returnMethod,
cart,
merchantData,
customerId,
language,
} = Object.assign(defaultValues, _opts);
Expand All @@ -37,6 +38,7 @@ module.exports = {
returnUrl,
returnMethod,
cart,
merchantData,
customerId,
language,
};
Expand Down Expand Up @@ -71,27 +73,25 @@ module.exports = {
};
},
init: (_opts) => {
const defaultValues = {
currency: "CZK",
};

const {
merchantId,
orderNo,
clientIp,
totalAmount,
currency,
description,
origPayId,
} = Object.assign(defaultValues, _opts);
merchantData,
} = _opts;

return {
merchantId,
origPayId,
orderNo,
dttm: dttm(),
clientIp,
totalAmount,
currency,
description,
merchantData,
};
},
start: ({ payId, merchantId }) => ({
Expand Down Expand Up @@ -134,14 +134,16 @@ module.exports = {
"merchantData",
],
oneclick: {
echo: ["merchantId", "origPayId", "dttm"],
init: [
"merchantId",
"origPayId",
"orderNo",
"dttm",
"clientIp",
"totalAmount",
"currency",
"description",
"merchantData",
],
start: ["merchantId", "payId", "dttm"],
},
Expand All @@ -161,7 +163,8 @@ module.exports = {
echo: ["signature"],
response: ["paymentStatus", "authCode", "merchantData"],
oneclick: {
init: [],
echo: [],
init: ["totalAmount", "currency", "merchantData"],
start: [],
},
},
Expand Down

0 comments on commit a3fd374

Please sign in to comment.