0.1.6 • Published 11 months ago

simplepay-core v0.1.6

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

Code sample

import { SimpleConnectionClient } from 'simplepay-core';

getValidStartOptions(amount: number) {
  const callbackData = Buffer.from(
    JSON.stringify({
      transactionAmount: amount,
      dateTime: moment().toISOString(),
    }),
  ).toString('base64');
  //change url to your own callback url
  return {
    salt: 'FxDa5w314kLlNseq2sKuVwaqZshZT5d6',
    merchant: 'PUBLICTESTHUF',
    currency: 'HUF',
    customerEmail: 'jsmith@example.com',
    url: `http://localhost:3000/api/v1/simplepay/callback/${callbackData}`,
    language: 'HU',
    total: amount,
    methods: ['CARD'],
    orderRef: '101010516348232068125',
    sdkVersion:
      'SimplePayV2.1_Payment_PHP_SDK_2.0.7_190701:dd236896400d7463677a82a47f53e36e',
    timeout: new Date(moment().add(15, 'minutes').toISOString()),
  };
}
async startTransaction(amount: number) {
  const client = new SimpleConnectionClient({
    merchant: 'PUBLICTESTHUF',
    secret: 'FxDa5w314kLlNseq2sKuVwaqZshZT5d6',
    baseUrl: 'https://sandbox.simplepay.hu/payment/v2/',
  });
  return client
    .request('start', this.getValidStartOptions(amount))
    .then((res) => {
      console.log(res);
      return res;
    })
    .catch((err) => {
      console.log(err);
      return err;
    });
}
async callback(r: string, callbackDataBase64: string) {
  const response: {
    e: string;
    m: string;
    o: string;
    r: number;
    t: number;
  } = JSON.parse(Buffer.from(r, 'base64').toString());
  const callbackData: DepositMoneyRequest = JSON.parse(
    Buffer.from(callbackDataBase64, 'base64').toString(),
  );
  if (response.e === 'SUCCESS') {
    console.log('transactionAmount', callbackData['transactionAmount']);
  }
  return response;
}
0.1.4

11 months ago

0.1.6

11 months ago

0.1.5

11 months ago

0.1.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.1.3

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago