Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ npm-debug.log
*.iml
/.build
/.serverless
package-lock.json
12 changes: 10 additions & 2 deletions handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,11 @@ export class PaylineCore {
}

private async _runAction(client: any, action: string, args: any): Promise<any> {
//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 {
Expand Down
14 changes: 7 additions & 7 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type OperationsProperty<T> = {[key in Operation]:T};
export enum CURRENCIES {
EUR = 978,
USD = 840,
GBP = 826,
GBP = 826
}

export enum ACTIONS {
Expand All @@ -20,7 +20,7 @@ export enum ACTIONS {
}

export enum MODE {
CPT = "CPT",
CPT = "CPT"
}

export interface Wallet {
Expand All @@ -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 {
Expand All @@ -54,7 +54,7 @@ export interface Card {
cardPresent?: string,
cardholder?: string,
token?: string,
paymentData?: PaymentData,
paymentData?: PaymentData
}

export interface Payment {
Expand All @@ -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
}

/**
Expand Down
16 changes: 10 additions & 6 deletions src/payline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,17 @@ export default class Payline extends PaylineCore {

public async doReAuthorization(transactionID: string, payment: Payment, referencePrefix?: string,
currency?: CURRENCIES, order: Order = {}): Promise<TransactionResult> {
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<TransactionResult> {
Expand Down