simplepay-core
v0.1.6
Published
```sh import { SimpleConnectionClient } from 'simplepay-core';
Downloads
8
Readme
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: '[email protected]',
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;
}