shepa
Version:
Shepa is a online payment gateway
50 lines • 2.67 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const Driver_1 = require("../Driver");
const RequestMethod_1 = require("../RequestMethod");
class Merchant extends Driver_1.Driver {
constructor() {
super(...arguments);
this.tokenUrl = 'https://merchant.shepa.com/api/v1/token';
this.verifyUrl = 'https://merchant.shepa.com/api/v1/verify';
}
send(apiKey, amount, userInfo) {
return __awaiter(this, void 0, void 0, function* () {
let res = yield this.request(this.tokenUrl, RequestMethod_1.RequestMethod.POST, Object.assign({}, {
api: apiKey,
amount: amount,
email: userInfo === null || userInfo === void 0 ? void 0 : userInfo.email,
mobile: userInfo === null || userInfo === void 0 ? void 0 : userInfo.mobile,
resellerId: '1000000012',
callback: userInfo === null || userInfo === void 0 ? void 0 : userInfo.callback,
description: userInfo === null || userInfo === void 0 ? void 0 : userInfo.description
}));
if (res.data.success)
return res.data.result;
throw new Error(res.data.error);
});
}
verify(apiKey, token, amount) {
return __awaiter(this, void 0, void 0, function* () {
let res = yield this.request(this.verifyUrl, RequestMethod_1.RequestMethod.POST, Object.assign({}, {
api: apiKey,
token: token,
amount: amount
}));
if (res.data.success)
return res.data.result;
throw new Error('خطا در ارسال اطلاعات به Shepa.com. لطفا از برقرار بودن اینترنت و در دسترس بودن Shepa.com اطمینان حاصل کنید');
});
}
}
exports.default = Merchant;
//# sourceMappingURL=Merchant.js.map