irpayments
Advanced tools
Comparing version 1.9.1 to 1.9.5
@@ -1,2 +0,30 @@ | ||
export default class zarinpal { | ||
export * from "./Errors"; | ||
export default class ZarinPal { | ||
private _merchant; | ||
private _isToman; | ||
private _isSandbox; | ||
private _requestLink; | ||
private _verifyLink; | ||
private _unVerifiedLink; | ||
private _gateway; | ||
private _currency; | ||
constructor(_merchant: string, _isToman?: boolean, _isSandbox?: boolean); | ||
create({ amount, description, callback_url, mobile, email, }: CreateType): Promise<{ | ||
data: any; | ||
errors: any; | ||
}>; | ||
verify({ authority, amount }: VerifyType): Promise<any>; | ||
unverified(): Promise<any>; | ||
} | ||
interface CreateType { | ||
amount: number; | ||
callback_url: string; | ||
description?: string; | ||
mobile?: string; | ||
email?: string; | ||
order_id?: string; | ||
} | ||
interface VerifyType { | ||
amount: number; | ||
authority: string; | ||
} |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
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()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class zarinpal { | ||
const axios_1 = __importDefault(require("axios")); | ||
__exportStar(require("./Errors"), exports); | ||
class ZarinPal { | ||
constructor(_merchant, _isToman = false, _isSandbox = false) { | ||
this._merchant = _merchant; | ||
this._isToman = _isToman; | ||
this._isSandbox = _isSandbox; | ||
this._requestLink = "https://api.zarinpal.com/pg/v4/payment/request.json"; | ||
this._verifyLink = "https://api.zarinpal.com/pg/v4/payment/verify.json"; | ||
this._unVerifiedLink = "https://api.zarinpal.com/pg/v4/payment/unVerified.json"; | ||
this._gateway = "https://www.zarinpal.com/pg/StartPay"; | ||
this._currency = "IRR"; | ||
if (!_merchant || _merchant.length > 36 || _merchant.length < 36) { | ||
throw new Error("Zarinpal Pay --> Merchant ID is invalid!"); | ||
} | ||
if (this._isSandbox) { | ||
this._requestLink = | ||
"https://sandbox.zarinpal.com/pg/v4/payment/request.json"; | ||
this._verifyLink = | ||
"https://sandbox.zarinpal.com/pg/v4/payment/verify.json"; | ||
this._gateway = "https://sandbox.zarinpal.com/pg/StartPay"; | ||
} | ||
if (_isToman) { | ||
this._currency = "IRT"; | ||
} | ||
} | ||
create({ amount, description, callback_url, mobile, email, }) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield axios_1.default.post(this._requestLink, { | ||
merchant_id: this._merchant, | ||
amount, | ||
currency: this._currency, | ||
description, | ||
callback_url, | ||
metadata: [mobile, email], | ||
}); | ||
if ((_a = data.errors) === null || _a === void 0 ? void 0 : _a.length) { | ||
throw new Error(`${JSON.stringify(data.errors)}`); | ||
} | ||
return { | ||
data: Object.assign(Object.assign({}, data.data), { link: `${this._gateway}/${data.data.authority}` }), | ||
errors: data.errors, | ||
}; | ||
}); | ||
} | ||
verify({ authority, amount }) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield axios_1.default.post(this._verifyLink, { | ||
merchant_id: this._merchant, | ||
amount, | ||
authority, | ||
}); | ||
if ((_a = data.errors) === null || _a === void 0 ? void 0 : _a.length) { | ||
throw new Error(`${JSON.stringify(data.errors)}`); | ||
} | ||
return data; | ||
}); | ||
} | ||
unverified() { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield axios_1.default.post(this._unVerifiedLink, { | ||
merchant_id: this._merchant, | ||
}); | ||
if ((_a = data.errors) === null || _a === void 0 ? void 0 : _a.length) { | ||
throw new Error(`Z${JSON.stringify(data.errors)}`); | ||
} | ||
return data; | ||
}); | ||
} | ||
} | ||
exports.default = zarinpal; | ||
exports.default = ZarinPal; |
{ | ||
"name": "irpayments", | ||
"version": "1.9.1", | ||
"version": "1.9.5", | ||
"description": "IR Payments, a package for all payment gateways of IRAN", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
@@ -13,3 +13,3 @@ # 💲 | IRPayments | ||
## 📂 | Documents | ||
Documents of this Package is live at [/irpayments](https://ehsan.js.org/irpayments/) | ||
Documents of this Package is live at [/irpayments](https://ehsan.js.org/IRPayments/) | ||
@@ -30,2 +30,2 @@ ## ✍ | Examples | ||
## 📄 | License | ||
[MIT](https://github.com/EhsanFox/irpayments/blob/main/LICENSE) | ||
[MIT](https://github.com/EhsanFox/irpayments/blob/main/LICENSE) |
31717
24
720
30