Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/api/apm-specific/baloto.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { determineError } from '../../services/errors.js';
import { post } from '../../services/http.js';
import { encodePathSegment } from '../../services/utils.js';

// Path segments appended to the API base (config.host).
const APMS_PATH = 'apms';
Expand Down Expand Up @@ -27,12 +28,13 @@ export default class Baloto {
* @param {string} id Payment id.
* @memberof Baloto
* @return {Promise<Object>} A promise to the Baloto response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async succeed(id) {
try {
const response = await post(
this.config.httpClient,
`${this.config.host}/${APMS_PATH}/${BALOTO_PATH}/${PAYMENTS_PATH}/${id}/${SUCCEED_PATH}`,
`${this.config.host}/${APMS_PATH}/${BALOTO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${SUCCEED_PATH}`,
this.config,
this.config.sk
);
Expand All @@ -49,12 +51,13 @@ export default class Baloto {
* @param {string} id Payment id.
* @memberof Baloto
* @return {Promise<Object>} A promise to the Baloto response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async expire(id) {
try {
const response = await post(
this.config.httpClient,
`${this.config.host}/${APMS_PATH}/${BALOTO_PATH}/${PAYMENTS_PATH}/${id}/${EXPIRE_PATH}`,
`${this.config.host}/${APMS_PATH}/${BALOTO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${EXPIRE_PATH}`,
this.config,
this.config.sk
);
Expand Down
7 changes: 5 additions & 2 deletions src/api/apm-specific/boleto.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { determineError } from '../../services/errors.js';
import { post } from '../../services/http.js';
import { encodePathSegment } from '../../services/utils.js';

// Path segments appended to the API base (config.host).
const APMS_PATH = 'apms';
Expand Down Expand Up @@ -27,12 +28,13 @@ export default class Boleto {
* @param {string} id Payment id.
* @memberof Boleto
* @return {Promise<Object>} A promise to the Boleto response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async succeed(id) {
try {
const response = await post(
this.config.httpClient,
`${this.config.host}/${APMS_PATH}/${BOLETO_PATH}/${PAYMENTS_PATH}/${id}/${SUCCEED_PATH}`,
`${this.config.host}/${APMS_PATH}/${BOLETO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${SUCCEED_PATH}`,
this.config,
this.config.sk
);
Expand All @@ -49,12 +51,13 @@ export default class Boleto {
* @param {string} id Payment id.
* @memberof Boleto
* @return {Promise<Object>} A promise to the Boleto response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async expire(id) {
try {
const response = await post(
this.config.httpClient,
`${this.config.host}/${APMS_PATH}/${BOLETO_PATH}/${PAYMENTS_PATH}/${id}/${EXPIRE_PATH}`,
`${this.config.host}/${APMS_PATH}/${BOLETO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${EXPIRE_PATH}`,
this.config,
this.config.sk
);
Expand Down
7 changes: 5 additions & 2 deletions src/api/apm-specific/fawry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { determineError } from '../../services/errors.js';
import { put } from '../../services/http.js';
import { encodePathSegment } from '../../services/utils.js';

// Path segments appended to the API base (config.host).
const APPROVAL_PATH = 'approval';
Expand Down Expand Up @@ -27,12 +28,13 @@ export default class Fawry {
* @param {string} reference Reference.
* @memberof Fawry
* @return {Promise<Object>} A promise to the Fawry response.
* @throws {ValueError} If reference is undefined, null, empty, "." or "..".
*/
async approve(reference) {
try {
const response = await put(
this.config.httpClient,
`${this.config.host}/${FAWRY_PATH}/${PAYMENTS_PATH}/${reference}/${APPROVAL_PATH}`,
`${this.config.host}/${FAWRY_PATH}/${PAYMENTS_PATH}/${encodePathSegment(reference, 'reference')}/${APPROVAL_PATH}`,
this.config,
this.config.sk
);
Expand All @@ -49,12 +51,13 @@ export default class Fawry {
* @param {string} reference Reference.
* @memberof Fawry
* @return {Promise<Object>} A promise to the Fawry response.
* @throws {ValueError} If reference is undefined, null, empty, "." or "..".
*/
async cancel(reference) {
try {
const response = await put(
this.config.httpClient,
`${this.config.host}/${FAWRY_PATH}/${PAYMENTS_PATH}/${reference}/${CANCELLATION_PATH}`,
`${this.config.host}/${FAWRY_PATH}/${PAYMENTS_PATH}/${encodePathSegment(reference, 'reference')}/${CANCELLATION_PATH}`,
this.config,
this.config.sk
);
Expand Down
16 changes: 10 additions & 6 deletions src/api/apm-specific/klarna.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { determineError } from '../../services/errors.js';
import { get, post } from '../../services/http.js';
import { encodePathSegment } from '../../services/utils.js';

// Path segments appended to the API base (config.host).
const CAPTURES_PATH = 'captures';
Expand Down Expand Up @@ -49,11 +50,12 @@ export default class Klarna {
*
* @param {string} id Session id.
* @return {Promise<Object>} A promise to the Klarna response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async getSession(id) {
const url = this.config.host.includes('sandbox')
? `${this.config.host}/${KLARNA_EXTERNAL_PATH}/${CREDIT_SESSIONS_PATH}/${id}`
: `${this.config.host}/${KLARNA_PATH}/${CREDIT_SESSIONS_PATH}/${id}`;
? `${this.config.host}/${KLARNA_EXTERNAL_PATH}/${CREDIT_SESSIONS_PATH}/${encodePathSegment(id, 'id')}`
: `${this.config.host}/${KLARNA_PATH}/${CREDIT_SESSIONS_PATH}/${encodePathSegment(id, 'id')}`;
try {
const response = await get(this.config.httpClient, url, this.config, this.config.sk);
return await response.json;
Expand All @@ -68,11 +70,12 @@ export default class Klarna {
* @param {string} id Payment id.
* @param {Object} body Capture details.
* @return {Promise<Object>} A promise to the Klarna response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async capture(id, body) {
const url = this.config.host.includes('sandbox')
? `${this.config.host}/${KLARNA_EXTERNAL_PATH}/${ORDERS_PATH}/${id}/${CAPTURES_PATH}`
: `${this.config.host}/${KLARNA_PATH}/${ORDERS_PATH}/${id}/${CAPTURES_PATH}`;
? `${this.config.host}/${KLARNA_EXTERNAL_PATH}/${ORDERS_PATH}/${encodePathSegment(id, 'id')}/${CAPTURES_PATH}`
: `${this.config.host}/${KLARNA_PATH}/${ORDERS_PATH}/${encodePathSegment(id, 'id')}/${CAPTURES_PATH}`;
try {
const response = await post(
this.config.httpClient,
Expand All @@ -93,11 +96,12 @@ export default class Klarna {
* @param {string} id Payment id.
* @param {Object} [body] Void details.
* @return {Promise<Object>} A promise to the Klarna response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async void(id, body) {
const url = this.config.host.includes('sandbox')
? `${this.config.host}/${KLARNA_EXTERNAL_PATH}/${ORDERS_PATH}/${id}/${VOIDS_PATH}`
: `${this.config.host}/${KLARNA_PATH}/${ORDERS_PATH}/${id}/${VOIDS_PATH}`;
? `${this.config.host}/${KLARNA_EXTERNAL_PATH}/${ORDERS_PATH}/${encodePathSegment(id, 'id')}/${VOIDS_PATH}`
: `${this.config.host}/${KLARNA_PATH}/${ORDERS_PATH}/${encodePathSegment(id, 'id')}/${VOIDS_PATH}`;
try {
const response = await post(
this.config.httpClient,
Expand Down
7 changes: 5 additions & 2 deletions src/api/apm-specific/oxxo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { determineError } from '../../services/errors.js';
import { post } from '../../services/http.js';
import { encodePathSegment } from '../../services/utils.js';

// Path segments appended to the API base (config.host).
const APMS_PATH = 'apms';
Expand Down Expand Up @@ -27,12 +28,13 @@ export default class Oxxo {
* @param {string} id Payment id.
* @memberof Oxxo
* @return {Promise<Object>} A promise to the Oxxo response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async succeed(id) {
try {
const response = await post(
this.config.httpClient,
`${this.config.host}/${APMS_PATH}/${OXXO_PATH}/${PAYMENTS_PATH}/${id}/${SUCCEED_PATH}`,
`${this.config.host}/${APMS_PATH}/${OXXO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${SUCCEED_PATH}`,
this.config,
this.config.sk
);
Expand All @@ -49,12 +51,13 @@ export default class Oxxo {
* @param {string} id Payment id.
* @memberof Oxxo
* @return {Promise<Object>} A promise to the Oxxo response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async expire(id) {
try {
const response = await post(
this.config.httpClient,
`${this.config.host}/${APMS_PATH}/${OXXO_PATH}/${PAYMENTS_PATH}/${id}/${EXPIRE_PATH}`,
`${this.config.host}/${APMS_PATH}/${OXXO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${EXPIRE_PATH}`,
this.config,
this.config.sk
);
Expand Down
7 changes: 5 additions & 2 deletions src/api/apm-specific/pagofacil.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { determineError } from '../../services/errors.js';
import { post } from '../../services/http.js';
import { encodePathSegment } from '../../services/utils.js';

// Path segments appended to the API base (config.host).
const APMS_PATH = 'apms';
Expand Down Expand Up @@ -27,12 +28,13 @@ export default class PagoFacil {
* @param {string} id Payment id.
* @memberof PagoFacil
* @return {Promise<Object>} A promise to the PagoFacil response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async succeed(id) {
try {
const response = await post(
this.config.httpClient,
`${this.config.host}/${APMS_PATH}/${PAGOFACIL_PATH}/${PAYMENTS_PATH}/${id}/${SUCCEED_PATH}`,
`${this.config.host}/${APMS_PATH}/${PAGOFACIL_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${SUCCEED_PATH}`,
this.config,
this.config.sk
);
Expand All @@ -49,12 +51,13 @@ export default class PagoFacil {
* @param {string} id Payment id.
* @memberof PagoFacil
* @return {Promise<Object>} A promise to the PagoFacil response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async expire(id) {
try {
const response = await post(
this.config.httpClient,
`${this.config.host}/${APMS_PATH}/${PAGOFACIL_PATH}/${PAYMENTS_PATH}/${id}/${EXPIRE_PATH}`,
`${this.config.host}/${APMS_PATH}/${PAGOFACIL_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${EXPIRE_PATH}`,
this.config,
this.config.sk
);
Expand Down
7 changes: 5 additions & 2 deletions src/api/apm-specific/rapipago.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { determineError } from '../../services/errors.js';
import { post } from '../../services/http.js';
import { encodePathSegment } from '../../services/utils.js';

// Path segments appended to the API base (config.host).
const APMS_PATH = 'apms';
Expand Down Expand Up @@ -27,12 +28,13 @@ export default class Rapipago {
* @param {string} id Payment id.
* @memberof Rapipago
* @return {Promise<Object>} A promise to the Rapipago response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async succeed(id) {
try {
const response = await post(
this.config.httpClient,
`${this.config.host}/${APMS_PATH}/${RAPIPAGO_PATH}/${PAYMENTS_PATH}/${id}/${SUCCEED_PATH}`,
`${this.config.host}/${APMS_PATH}/${RAPIPAGO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${SUCCEED_PATH}`,
this.config,
this.config.sk
);
Expand All @@ -49,12 +51,13 @@ export default class Rapipago {
* @param {string} id Payment id.
* @memberof Rapipago
* @return {Promise<Object>} A promise to the Rapipago response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async expire(id) {
try {
const response = await post(
this.config.httpClient,
`${this.config.host}/${APMS_PATH}/${RAPIPAGO_PATH}/${PAYMENTS_PATH}/${id}/${EXPIRE_PATH}`,
`${this.config.host}/${APMS_PATH}/${RAPIPAGO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${EXPIRE_PATH}`,
this.config,
this.config.sk
);
Expand Down
21 changes: 13 additions & 8 deletions src/api/apm-specific/sepa.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { determineError } from '../../services/errors.js';
import { get, post } from '../../services/http.js';
import { encodePathSegment } from '../../services/utils.js';

// Path segments appended to the API base (config.host).
const CANCEL_PATH = 'cancel';
Expand All @@ -24,11 +25,12 @@ export default class Sepa {
*
* @param {string} id Source id
* @return {Promise<Object>} A promise to the Sepa response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async getMandate(id) {
const url = this.config.host.includes('sandbox')
? `${this.config.host}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${id}`
: `${this.config.host}/${SEPA_PATH}/${MANDATES_PATH}/${id}`;
? `${this.config.host}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}`
: `${this.config.host}/${SEPA_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}`;
try {
const response = await get(this.config.httpClient, url, this.config, this.config.sk);
return await response.json;
Expand All @@ -42,11 +44,12 @@ export default class Sepa {
*
* @param {string} id Source id
* @return {Promise<Object>} A promise to the Sepa response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async cancelMandate(id) {
const url = this.config.host.includes('sandbox')
? `${this.config.host}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${id}/${CANCEL_PATH}`
: `${this.config.host}/${SEPA_PATH}/${MANDATES_PATH}/${id}/${CANCEL_PATH}`;
? `${this.config.host}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}/${CANCEL_PATH}`
: `${this.config.host}/${SEPA_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}/${CANCEL_PATH}`;

try {
const response = await post(this.config.httpClient, url, this.config, this.config.sk);
Expand All @@ -61,11 +64,12 @@ export default class Sepa {
*
* @param {string} id Source id
* @return {Promise<Object>} A promise to the Sepa response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async getPPROMandate(id) {
const url = this.config.host.includes('sandbox')
? `${this.config.host}/${PPRO_PATH}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${id}`
: `${this.config.host}/${PPRO_PATH}/${SEPA_PATH}/${MANDATES_PATH}/${id}`;
? `${this.config.host}/${PPRO_PATH}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}`
: `${this.config.host}/${PPRO_PATH}/${SEPA_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}`;
try {
const response = await get(this.config.httpClient, url, this.config, this.config.sk);
return await response.json;
Expand All @@ -79,11 +83,12 @@ export default class Sepa {
*
* @param {string} id Source id
* @return {Promise<Object>} A promise to the Sepa response.
* @throws {ValueError} If id is undefined, null, empty, "." or "..".
*/
async cancelPPROMandate(id) {
const url = this.config.host.includes('sandbox')
? `${this.config.host}/${PPRO_PATH}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${id}/${CANCEL_PATH}`
: `${this.config.host}/${PPRO_PATH}/${SEPA_PATH}/${MANDATES_PATH}/${id}/${CANCEL_PATH}`;
? `${this.config.host}/${PPRO_PATH}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}/${CANCEL_PATH}`
: `${this.config.host}/${PPRO_PATH}/${SEPA_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}/${CANCEL_PATH}`;

try {
const response = await post(this.config.httpClient, url, this.config, this.config.sk);
Expand Down
Loading
Loading