1.0.9 • Published 2 years ago

paytrail-lib v1.0.9

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

Node, typescript - paytrail-lib

This module allows you to create payments with Paytrail REST-api https://docs-old.paytrail.com/legacy/rest-interface/payment-creation/.

Usage

installation:

npm i paytrail-lib

Example usage to create payment with price:

const PaytrailLib = require("paytrail-lib");

const paytrail = new PaytrailLib(
  "13466",
  "6pKF4jkv97zmqBJ3ZL8gUw5DfT2NMQ",
  {
    success: "https://www.domain.com",
    failure: "https://www.domain.com",
    notification: "https://www.domain.com"
  }
);
const paymentWithPrice = {
  orderNumber: "12345678",
  price: 499999.99
};
paytrail.createPayment(paymentWithPrice).then(({orderNumber, token, url}) => {
  console.log(orderNumber, token, url);
  }
).catch(error => {console.log(error.message)});

Documentation

constructor

paramvalue
merchantIdstring!
merchantSecretstring!
urlSet{success: string!, notification: string!, failure: string!}
const PaytrailLib = require("paytrail-lib");

const paytrail = new PaytrailLib("13466", "6pKF4jkv97zmqBJ3ZL8gUw5DfT2NMQ", {
  success: "https://www.domain.com",
  failure: "https://www.domain.com",
  notification: "https://www.domain.com"
});

createPayment : Promise | never

paramvalue
orderNumberstring!
referenceNumberstring? (READ doc: https://docs.paytrail.com/en/ch04s05.html)
descriptionstring?
currencystring? (default: EUR)
localestring? (default: fi_FI)
orderDetails{invludeVat: boolean!, products[]: {title: string!, code: string?, amount: number, price: number, vat: number, discount:number?, type?: (number, default 1) }!,contact:{firstName:string, lastName: string, companyName: string?, email: string, telephone: string?, mobile: string?, {address: {street: string!, postalCode!, postalOffice!, country: string!}!}}!}?;
pricenumber? (Note: you only can have price if you dont have orderDetails)
const paymentWithPrice = {
  orderNumber: "12345678",
  price: 499999.99
};
try {
  const { url, token, orderNumber } = await paytrail.createPayment(
    paymentWithPrice
  );
} catch {
  //
}

const paymentWithOrderDetails = {
  orderNumber: "12345678",
  description: "Cat",
  currency: "EUR",
  locale: "fi_FI",
  orderDetails: {
    includeVat: true,
    contact: {
      firstName: "Cat",
      lastName: "Cat",
      companyName: "Cat Oy",
      email: "cat@cat.com",
      telephone: "04123123123",
      mobile: "040404040440",
      address: {
        street: "Cat 1",
        postalCode: "123123",
        postalOffice: "CAt",
        country: "FI"
      }
    },
    products: [
      {
        title: "Cat",
        code: "Cat",
        amount: 100000,
        price: 0.78,
        vat: 23,
        discount: 0,
        type: 1
      }
    ]
  }
};
try {
  const { url: url2, token: token2, orderNumber: orderNumber2 } = await paytrail.createPayment(
    paymentWithOrderDetails
  );
} catch {
  //
}

confirmPayment: boolean

paramvalue
query{orderNumber: string!, timestamp: string!, paid: string?, method: number?, authCode: string!}
paytrail.confirmPayment({
  orderNumber: "ORDER-12345",
  payment: "12345678012",
  timestamp: "1212121212",
  paid: "asdfasdfas",
  method: 1,
  authCode: "3E7E4970AFF62A44145B5A71841FBC74"
});

confirmPaymentFromQuery : boolean

paramvalue
query{ORDER_NUMBER: string!, TIMESTAMP: string!, PAID: string?, METHOD: number?, RETURN_AUTHCODE: string!}
// koa and koa-router example
router.get("/return-path", ctx => {
  const result = paytrail.confirmPaymentFromQuery(ctx.query);
  ctx.body = `Payment confirmation: ${result} `;
});
1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago