diff --git a/.gitignore b/.gitignore index db14e0f..a4b16aa 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ npm-debug.log *.iml /.build /.serverless +package-lock.json \ No newline at end of file diff --git a/handler.ts b/handler.ts index c2979e7..ba9d7f2 100644 --- a/handler.ts +++ b/handler.ts @@ -7,8 +7,7 @@ import {CURRENCIES, Environment} from "./src/model"; const merchantId: string = process.env.MERCHANT_ID || "XXX"; const accessKey: string = process.env.ACCESS_KEY ||"XXX"; const contractId: string = process.env.CONTRACT_ID || "1234567"; -const environment: Environment = (process.env.ENVIRONMENT || "") === Environment.production ? - Environment.production : Environment.homologation; +const environment: Environment = (process.env.ENVIRONMENT || "") === Environment.production ? Environment.production : Environment.homologation; const currency: CURRENCIES = CURRENCIES[process.env.CURRENCY || ""] || CURRENCIES.USD; // instances @@ -75,6 +74,15 @@ export const doAuthorization = async (event, context, callback) => { event.referencePrefix, event.currency, event.order)); }; +// export const doReAuthorization = async (event, context, callback) => { +// // Get params from SNS payload +// let snsPayload = JSON.parse(event.Records[0].Sns.Message); +// console.log(snsPayload); +// // Execute function +// result(callback, await payline(snsPayload).doReAuthorization(snsPayload.transactionID, snsPayload.payment, +// snsPayload.referencePrefix, snsPayload.payment.currency, snsPayload.order)); +// }; + export const doReAuthorization = async (event, context, callback) => { result(callback, await payline(event).doReAuthorization(event.transactionID, event.payment, event.referencePrefix, event.currency, event.order)); diff --git a/src/core.ts b/src/core.ts index 0bbf324..7f4f81d 100644 --- a/src/core.ts +++ b/src/core.ts @@ -191,12 +191,11 @@ export class PaylineCore { } private async _runAction(client: any, action: string, args: any): Promise { - //args.version = args.version || this.paylineVersion; + // args.version = args.version || this.paylineVersion; const _args: any = this.ensureAttributes(args); const response = await client[this.actionMethodName(action)](_args); const result = this.extractResult(response); debug(`action ${action} got result ${JSON.stringify(result)} from response ${JSON.stringify(response)}`); - if (this.isResultSuccessful(result)) { return response; } else { diff --git a/src/model.ts b/src/model.ts index 2dc1e6b..ad14d89 100644 --- a/src/model.ts +++ b/src/model.ts @@ -10,7 +10,7 @@ export type OperationsProperty = {[key in Operation]:T}; export enum CURRENCIES { EUR = 978, USD = 840, - GBP = 826, + GBP = 826 } export enum ACTIONS { @@ -20,7 +20,7 @@ export enum ACTIONS { } export enum MODE { - CPT = "CPT", + CPT = "CPT" } export interface Wallet { @@ -33,13 +33,13 @@ export interface Wallet { comment?: string, default?: string, cardStatus?: string, - cardBrand?: string, + cardBrand?: string } export interface PaymentData { transactionID: string, network: string, - tokenData: string, + tokenData: string } export interface Card { @@ -54,7 +54,7 @@ export interface Card { cardPresent?: string, cardholder?: string, token?: string, - paymentData?: PaymentData, + paymentData?: PaymentData } export interface Payment { @@ -63,14 +63,14 @@ export interface Payment { action?: ACTIONS, mode?: MODE, contractNumber?: string, - softDescriptor?: string, + softDescriptor?: string } export interface Order { ref?: string, amount?: number, currency?: CURRENCIES, - date?: Date, + date?: Date } /** diff --git a/src/payline.ts b/src/payline.ts index 7de9156..aeebdc1 100644 --- a/src/payline.ts +++ b/src/payline.ts @@ -134,13 +134,17 @@ export default class Payline extends PaylineCore { public async doReAuthorization(transactionID: string, payment: Payment, referencePrefix?: string, currency?: CURRENCIES, order: Order = {}): Promise { - this.setPaymentDefaults(payment, ACTIONS.AUTHORIZATION, currency); + this.setPaymentDefaults(payment, ACTIONS.AUTHORIZATION, currency); this.setOrderDefaults(order, referencePrefix, currency, payment.amount); - return this.extractTransactionalResult(await this.runAction("doReAuthorization", { - transactionID, - payment, - order, - })); + try { + return this.extractTransactionalResult(await this.runAction("doReAuthorization", { + transactionID, + payment, + order + })); + } catch(err) { + console.log(err); + } } public async doCapture(transactionID, payment: Payment, currency?: CURRENCIES): Promise {