@unify-payment/node 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/index.d.mts +40 -2
- package/dist/index.d.ts +40 -2
- package/dist/index.js +7 -1
- package/dist/index.mjs +7 -1
- package/package.json +27 -12
package/README.md
CHANGED
|
@@ -15,9 +15,11 @@ UnifyPayment is a TypeScript package that provides a unified interface for integ
|
|
|
15
15
|
- **LemonSqueezy:** (Checkout, Webhook) will add more functionality later.
|
|
16
16
|
- **SSLCommerz:** (Checkout) will add more functionality later.
|
|
17
17
|
- **PayPal:** (Checkout) will add more functionality later.
|
|
18
|
+
- **Bkash:** (Checkout) will add more functionality later.
|
|
19
|
+
- **Nagad:** (Checkout) will add more functionality later.
|
|
18
20
|
- **RazorPay:** (upcoming).
|
|
21
|
+
- **Shopify:** (upcoming).
|
|
19
22
|
- **GooglePay:** (planing).
|
|
20
|
-
- **Shopify:** (planing).
|
|
21
23
|
|
|
22
24
|
## Installation
|
|
23
25
|
|
package/dist/index.d.mts
CHANGED
|
@@ -20,12 +20,12 @@ interface IBkashPayloadProps {
|
|
|
20
20
|
|
|
21
21
|
type TFetchOptions = {
|
|
22
22
|
method?: string;
|
|
23
|
-
headers?:
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
24
|
body?: BodyInit;
|
|
25
25
|
};
|
|
26
26
|
declare class UnifyFetch {
|
|
27
27
|
jsonFetch<T>(url: string, options?: TFetchOptions): Promise<[T, Response]>;
|
|
28
|
-
axios<T>(url: string, options?: TFetchOptions): Promise<
|
|
28
|
+
axios<T>(url: string, options?: TFetchOptions): Promise<[T, Request]>;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
declare class Bkash extends UnifyFetch {
|
|
@@ -194,6 +194,43 @@ declare class LemonSqueezy extends UnifyFetch {
|
|
|
194
194
|
}): Promise<TWebhookEventResponse>;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
interface INagadOptions {
|
|
198
|
+
merchant_id: string;
|
|
199
|
+
merchant_number: string;
|
|
200
|
+
private_key: string;
|
|
201
|
+
public_key: string;
|
|
202
|
+
callbackURL: string;
|
|
203
|
+
apiVersion: string;
|
|
204
|
+
is_live: boolean;
|
|
205
|
+
}
|
|
206
|
+
type INagadClientType = "PC_WEB" | "MOBILE_WEB" | "MOBILE_APP" | "WALLET_WEB_VIEW" | "BILL_KEY";
|
|
207
|
+
interface INagadCreatePaymentArgs {
|
|
208
|
+
orderId: string;
|
|
209
|
+
amount: string;
|
|
210
|
+
productDetails: Record<string, string>;
|
|
211
|
+
ip: string;
|
|
212
|
+
clientType: INagadClientType;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
declare class Nagad extends UnifyFetch {
|
|
216
|
+
private options;
|
|
217
|
+
constructor(options: INagadOptions);
|
|
218
|
+
private getApiBaseUrl;
|
|
219
|
+
private getMerchantId;
|
|
220
|
+
private getMerchantNumber;
|
|
221
|
+
private getPrivateKey;
|
|
222
|
+
private getPublicKey;
|
|
223
|
+
private getTimeStamp;
|
|
224
|
+
private getCallbackUrl;
|
|
225
|
+
private getApiHeaders;
|
|
226
|
+
private createHash;
|
|
227
|
+
private encrypt;
|
|
228
|
+
private decrypt;
|
|
229
|
+
private sign;
|
|
230
|
+
private confirmPayment;
|
|
231
|
+
getCheckoutUrl(options: INagadCreatePaymentArgs): Promise<string>;
|
|
232
|
+
}
|
|
233
|
+
|
|
197
234
|
interface IPaypalOptions {
|
|
198
235
|
clientId: string;
|
|
199
236
|
clientSecret: string;
|
|
@@ -340,6 +377,7 @@ declare const UnifyPayment: {
|
|
|
340
377
|
Paypal: typeof Paypal;
|
|
341
378
|
SSLCommerz: typeof SSLCommerz;
|
|
342
379
|
Stripe: typeof Stripe;
|
|
380
|
+
Nagad: typeof Nagad;
|
|
343
381
|
};
|
|
344
382
|
|
|
345
383
|
export { UnifyPayment };
|
package/dist/index.d.ts
CHANGED
|
@@ -20,12 +20,12 @@ interface IBkashPayloadProps {
|
|
|
20
20
|
|
|
21
21
|
type TFetchOptions = {
|
|
22
22
|
method?: string;
|
|
23
|
-
headers?:
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
24
|
body?: BodyInit;
|
|
25
25
|
};
|
|
26
26
|
declare class UnifyFetch {
|
|
27
27
|
jsonFetch<T>(url: string, options?: TFetchOptions): Promise<[T, Response]>;
|
|
28
|
-
axios<T>(url: string, options?: TFetchOptions): Promise<
|
|
28
|
+
axios<T>(url: string, options?: TFetchOptions): Promise<[T, Request]>;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
declare class Bkash extends UnifyFetch {
|
|
@@ -194,6 +194,43 @@ declare class LemonSqueezy extends UnifyFetch {
|
|
|
194
194
|
}): Promise<TWebhookEventResponse>;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
interface INagadOptions {
|
|
198
|
+
merchant_id: string;
|
|
199
|
+
merchant_number: string;
|
|
200
|
+
private_key: string;
|
|
201
|
+
public_key: string;
|
|
202
|
+
callbackURL: string;
|
|
203
|
+
apiVersion: string;
|
|
204
|
+
is_live: boolean;
|
|
205
|
+
}
|
|
206
|
+
type INagadClientType = "PC_WEB" | "MOBILE_WEB" | "MOBILE_APP" | "WALLET_WEB_VIEW" | "BILL_KEY";
|
|
207
|
+
interface INagadCreatePaymentArgs {
|
|
208
|
+
orderId: string;
|
|
209
|
+
amount: string;
|
|
210
|
+
productDetails: Record<string, string>;
|
|
211
|
+
ip: string;
|
|
212
|
+
clientType: INagadClientType;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
declare class Nagad extends UnifyFetch {
|
|
216
|
+
private options;
|
|
217
|
+
constructor(options: INagadOptions);
|
|
218
|
+
private getApiBaseUrl;
|
|
219
|
+
private getMerchantId;
|
|
220
|
+
private getMerchantNumber;
|
|
221
|
+
private getPrivateKey;
|
|
222
|
+
private getPublicKey;
|
|
223
|
+
private getTimeStamp;
|
|
224
|
+
private getCallbackUrl;
|
|
225
|
+
private getApiHeaders;
|
|
226
|
+
private createHash;
|
|
227
|
+
private encrypt;
|
|
228
|
+
private decrypt;
|
|
229
|
+
private sign;
|
|
230
|
+
private confirmPayment;
|
|
231
|
+
getCheckoutUrl(options: INagadCreatePaymentArgs): Promise<string>;
|
|
232
|
+
}
|
|
233
|
+
|
|
197
234
|
interface IPaypalOptions {
|
|
198
235
|
clientId: string;
|
|
199
236
|
clientSecret: string;
|
|
@@ -340,6 +377,7 @@ declare const UnifyPayment: {
|
|
|
340
377
|
Paypal: typeof Paypal;
|
|
341
378
|
SSLCommerz: typeof SSLCommerz;
|
|
342
379
|
Stripe: typeof Stripe;
|
|
380
|
+
Nagad: typeof Nagad;
|
|
343
381
|
};
|
|
344
382
|
|
|
345
383
|
export { UnifyPayment };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var K=Object.create;var m=Object.defineProperty,x=Object.defineProperties,D=Object.getOwnPropertyDescriptor,$=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertyNames,P=Object.getOwnPropertySymbols,z=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;var U=(s,t,e)=>t in s?m(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,y=(s,t)=>{for(var e in t||(t={}))R.call(t,e)&&U(s,e,t[e]);if(P)for(var e of P(t))M.call(t,e)&&U(s,e,t[e]);return s},T=(s,t)=>x(s,$(t));var F=(s,t)=>{for(var e in t)m(s,e,{get:t[e],enumerable:!0})},w=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of j(t))!R.call(s,a)&&a!==e&&m(s,a,{get:()=>t[a],enumerable:!(r=D(t,a))||r.enumerable});return s};var u=(s,t,e)=>(e=s!=null?K(z(s)):{},w(t||!s||!s.__esModule?m(e,"default",{value:s,enumerable:!0}):e,s)),H=s=>w(m({},"__esModule",{value:!0}),s);var i=(s,t,e)=>new Promise((r,a)=>{var n=p=>{try{c(e.next(p))}catch(l){a(l)}},h=p=>{try{c(e.throw(p))}catch(l){a(l)}},c=p=>p.done?r(p.value):Promise.resolve(p.value).then(n,h);c((e=e.apply(s,t)).next())});var L={};F(L,{UnifyPayment:()=>_});module.exports=H(L);var b=u(require("axios"));var o=class{jsonFetch(t,e){return i(this,null,function*(){let r=yield fetch(t,e);return[yield r.json(),r]})}axios(t,e){return i(this,null,function*(){let r=yield(0,b.default)({url:t,method:e==null?void 0:e.method,headers:e==null?void 0:e.headers,data:e==null?void 0:e.body});return[r.data,r.request]})}};var I=class extends o{constructor(e){super();this.options=e}getAppKey(){return this.options.app_key}getApiBaseUrl(){return this.options.apiUrl}getApiRequestHeaders(){return{"Content-Type":"application/json",Accept:"application/json",username:this.options.username,password:this.options.password}}getAccessToken(){return i(this,null,function*(){let[e]=yield this.jsonFetch(`${this.getApiBaseUrl()}/tokenized/checkout/token/grant`,{method:"POST",headers:this.getApiRequestHeaders(),body:JSON.stringify({app_key:this.options.app_key,app_secret:this.options.app_secret})});if("errorMessage"in e)throw new Error(e.errorMessage);return e.id_token})}getCheckoutUrl(e){return i(this,null,function*(){let r=yield this.getAccessToken(),[a]=yield this.jsonFetch(`${this.getApiBaseUrl()}/tokenized/checkout/create`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-App-Key":this.getAppKey(),Authorization:`Bearer ${r}`},body:JSON.stringify(e)});if("errorMessage"in a)throw new Error(a.errorMessage);return a.bkashURL})}};var v=class extends o{constructor(e){super();this.apiKey=e}getApiBaseUrl(){return"https://api.lemonsqueezy.com/v1"}getApiRequestHeaders(){return{Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:`Bearer ${this.apiKey}`}}getCheckoutUrl(e){return i(this,null,function*(){let[r]=yield this.jsonFetch(`${this.getApiBaseUrl()}/checkouts`,{method:"POST",body:JSON.stringify({data:e}),headers:this.getApiRequestHeaders()});if("errors"in r)throw new Error(r.errors[0].detail);return r.data.attributes.url})}verifySignature(e){return i(this,null,function*(){try{let r=new TextEncoder,a=yield crypto.subtle.importKey("raw",r.encode(e.secret),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),n=yield crypto.subtle.sign("HMAC",a,r.encode(e.body));if(Array.from(new Uint8Array(n)).map(c=>c.toString(16).padStart(2,"0")).join("")!==e.signature)throw new Error("Invalid signature");return{event:JSON.parse(e.body),type:e.x_event}}catch(r){return{error:r}}})}};var A=u(require("dayjs")),B=u(require("dayjs/plugin/timezone")),E=u(require("dayjs/plugin/utc"));var g=u(require("crypto")),N=u(require("node-rsa"));var k=class extends o{constructor(e){super();this.options=e;A.default.extend(B.default),A.default.extend(E.default)}getApiBaseUrl(){return this.options.is_live?"https://api.mynagad.com/api/dfs":"http://sandbox.mynagad.com:10080/remote-payment-gateway-1.0/api/dfs"}getMerchantId(){return this.options.merchant_id}getMerchantNumber(){return this.options.merchant_number}getPrivateKey(){return this.options.private_key}getPublicKey(){return this.options.public_key}getTimeStamp(){return(0,A.default)().tz("Asia/Dhaka").format("YYYYMMDDHHmmss")}getCallbackUrl(){return this.options.callbackURL}getApiHeaders(){return{Accept:"application/json","Content-Type":"application/json","X-KM-Api-Version":this.options.apiVersion}}createHash(e){return g.default.createHash("sha1").update(e).digest("hex").toUpperCase()}encrypt(e){let r=`-----BEGIN PUBLIC KEY-----
|
|
2
|
+
${this.getPublicKey()}
|
|
3
|
+
-----END PUBLIC KEY-----`;return g.default.publicEncrypt({key:r,padding:g.default.constants.RSA_PKCS1_PADDING},Buffer.from(JSON.stringify(e),"utf8")).toString("base64")}decrypt(e){let r=`-----BEGIN PRIVATE KEY-----
|
|
4
|
+
${this.getPrivateKey()}
|
|
5
|
+
-----END PRIVATE KEY-----`,a=new N.default(r,"pkcs8",{encryptionScheme:"pkcs1"});a.setOptions({environment:"browser"});let n=a.decrypt(e).toString("utf8");return JSON.parse(n)}sign(e){let r=`-----BEGIN PRIVATE KEY-----
|
|
6
|
+
${this.getPrivateKey()}
|
|
7
|
+
-----END PRIVATE KEY-----`,a=g.default.createSign("SHA256");return a.update(JSON.stringify(e)),a.end(),a.sign(r,"base64")}confirmPayment(e){return i(this,null,function*(){let r={currencyCode:"050",amount:e.amount,orderId:e.orderId,challenge:e.challenge,merchantId:this.getMerchantId()},a={signature:this.sign(r),paymentRefId:e.paymentReferenceId,sensitiveData:this.encrypt(r),merchantCallbackURL:this.getCallbackUrl(),additionalMerchantInfo:y({},e.productDetails)},[n]=yield this.axios(`${this.getApiBaseUrl()}/check-out/complete/${e.paymentReferenceId}`,{method:"POST",headers:T(y({},this.getApiHeaders()),{"X-KM-IP-V4":e.ip,"X-KM-Client-Type":e.clientType}),body:JSON.stringify(a)});return n})}getCheckoutUrl(e){return i(this,null,function*(){let r=this.getTimeStamp(),a=`${this.getApiBaseUrl()}/check-out/initialize/${this.getMerchantId()}/${e.orderId}`,n={datetime:r,orderId:e.orderId,merchantId:this.getMerchantId(),challenge:this.createHash(e.orderId)},h={dateTime:r,signature:this.sign(n),sensitiveData:this.encrypt(n),accountNumber:this.getMerchantNumber()},[c]=yield this.axios(a,{method:"POST",headers:T(y({},this.getApiHeaders()),{"X-KM-IP-V4":e.ip,"X-KM-Client-Type":e.clientType}),body:JSON.stringify(h)}),p=this.decrypt(c.sensitiveData);return(yield this.confirmPayment({ip:e.ip,challenge:p.challenge,amount:e.amount,orderId:e.orderId,clientType:e.clientType,paymentReferenceId:p.paymentReferenceId,productDetails:e.productDetails})).callBackUrl})}};var f=class extends o{constructor(e){super();this.options=e}getApiBaseUrl(){return this.options.sandbox?"https://api-m.sandbox.paypal.com":"https://api.paypal.com"}getClientId(){return this.options.clientId}getClientSecret(){return this.options.clientSecret}getApiCheckoutUrl(){return`${this.getApiBaseUrl()}/v2/checkout/orders`}getAccessToken(){return i(this,null,function*(){let e=`${this.getApiBaseUrl()}/v1/oauth2/token`,r=btoa(`${this.getClientId()}:${this.getClientSecret()}`),[a]=yield this.jsonFetch(e,{method:"POST",headers:{Authorization:`Basic ${r}`,"Content-Type":"application/x-www-form-urlencoded"},body:"grant_type=client_credentials"});return a.access_token})}getCheckoutUrl(e){return i(this,null,function*(){var h;let r=yield this.getAccessToken(),[a]=yield this.jsonFetch(this.getApiCheckoutUrl(),{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`}}),n=(h=a.links.find(c=>c.rel==="approve"))==null?void 0:h.href;if(!n)throw new Error("Failed to get checkout url");return n})}};var S=class extends o{constructor(e){super();this.options=e}getApiBaseUrl(){return this.options.apiUrl}getApiCheckoutUrl(){return`${this.getApiBaseUrl()}/gwprocess/v4/api.php`}getApiValidationUrl(){return`${this.getApiBaseUrl()}/validator/api/validationserverAPI.php`}getApiRefundUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiRefundQueryUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiTransactionQueryBySessionIdUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiTransactionQueryByTransactionIdUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiHeaders(){return{"Content-Type":"application/x-www-form-urlencoded"}}urlFormEncode(e){return Object.entries(e).map(([r,a])=>`${encodeURIComponent(r)}=${encodeURIComponent(a)}`).join("&")}getCheckoutUrl(e){return i(this,null,function*(){let[r]=yield this.jsonFetch(this.getApiCheckoutUrl(),{method:"POST",body:this.urlFormEncode(e),headers:this.getApiHeaders()});if(r.status==="FAILED")throw new Error(r.failedreason);return r.redirectGatewayURL})}};var O=require("stripe");var C=class{constructor(t,e){this.apiKey=t;this.stripe=new O.Stripe(t,e)}getCheckoutUrl(t){return i(this,null,function*(){let e=yield this.stripe.checkout.sessions.create(t);if(!e.url)throw new Error("Failed to get checkout url");return e.url})}verifySignature(t){return i(this,null,function*(){try{return{event:yield this.stripe.webhooks.constructEventAsync(t.body,t.signature,t.secret)}}catch(e){return{error:e}}})}};var _={LemonSqueezy:v,Bkash:I,Paypal:f,SSLCommerz:S,Stripe:C,Nagad:k};0&&(module.exports={UnifyPayment});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
var r=(
|
|
1
|
+
var U=Object.defineProperty,R=Object.defineProperties;var w=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var P=(i,r,e)=>r in i?U(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e,g=(i,r)=>{for(var e in r||(r={}))b.call(r,e)&&P(i,e,r[e]);if(T)for(var e of T(r))B.call(r,e)&&P(i,e,r[e]);return i},S=(i,r)=>R(i,w(r));var a=(i,r,e)=>new Promise((t,s)=>{var n=p=>{try{c(e.next(p))}catch(m){s(m)}},h=p=>{try{c(e.throw(p))}catch(m){s(m)}},c=p=>p.done?t(p.value):Promise.resolve(p.value).then(n,h);c((e=e.apply(i,r)).next())});import E from"axios";var o=class{jsonFetch(r,e){return a(this,null,function*(){let t=yield fetch(r,e);return[yield t.json(),t]})}axios(r,e){return a(this,null,function*(){let t=yield E({url:r,method:e==null?void 0:e.method,headers:e==null?void 0:e.headers,data:e==null?void 0:e.body});return[t.data,t.request]})}};var l=class extends o{constructor(e){super();this.options=e}getAppKey(){return this.options.app_key}getApiBaseUrl(){return this.options.apiUrl}getApiRequestHeaders(){return{"Content-Type":"application/json",Accept:"application/json",username:this.options.username,password:this.options.password}}getAccessToken(){return a(this,null,function*(){let[e]=yield this.jsonFetch(`${this.getApiBaseUrl()}/tokenized/checkout/token/grant`,{method:"POST",headers:this.getApiRequestHeaders(),body:JSON.stringify({app_key:this.options.app_key,app_secret:this.options.app_secret})});if("errorMessage"in e)throw new Error(e.errorMessage);return e.id_token})}getCheckoutUrl(e){return a(this,null,function*(){let t=yield this.getAccessToken(),[s]=yield this.jsonFetch(`${this.getApiBaseUrl()}/tokenized/checkout/create`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-App-Key":this.getAppKey(),Authorization:`Bearer ${t}`},body:JSON.stringify(e)});if("errorMessage"in s)throw new Error(s.errorMessage);return s.bkashURL})}};var y=class extends o{constructor(e){super();this.apiKey=e}getApiBaseUrl(){return"https://api.lemonsqueezy.com/v1"}getApiRequestHeaders(){return{Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:`Bearer ${this.apiKey}`}}getCheckoutUrl(e){return a(this,null,function*(){let[t]=yield this.jsonFetch(`${this.getApiBaseUrl()}/checkouts`,{method:"POST",body:JSON.stringify({data:e}),headers:this.getApiRequestHeaders()});if("errors"in t)throw new Error(t.errors[0].detail);return t.data.attributes.url})}verifySignature(e){return a(this,null,function*(){try{let t=new TextEncoder,s=yield crypto.subtle.importKey("raw",t.encode(e.secret),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),n=yield crypto.subtle.sign("HMAC",s,t.encode(e.body));if(Array.from(new Uint8Array(n)).map(c=>c.toString(16).padStart(2,"0")).join("")!==e.signature)throw new Error("Invalid signature");return{event:JSON.parse(e.body),type:e.x_event}}catch(t){return{error:t}}})}};import C from"dayjs";import N from"dayjs/plugin/timezone";import O from"dayjs/plugin/utc";import I from"node:crypto";import K from"node-rsa";var v=class extends o{constructor(e){super();this.options=e;C.extend(N),C.extend(O)}getApiBaseUrl(){return this.options.is_live?"https://api.mynagad.com/api/dfs":"http://sandbox.mynagad.com:10080/remote-payment-gateway-1.0/api/dfs"}getMerchantId(){return this.options.merchant_id}getMerchantNumber(){return this.options.merchant_number}getPrivateKey(){return this.options.private_key}getPublicKey(){return this.options.public_key}getTimeStamp(){return C().tz("Asia/Dhaka").format("YYYYMMDDHHmmss")}getCallbackUrl(){return this.options.callbackURL}getApiHeaders(){return{Accept:"application/json","Content-Type":"application/json","X-KM-Api-Version":this.options.apiVersion}}createHash(e){return I.createHash("sha1").update(e).digest("hex").toUpperCase()}encrypt(e){let t=`-----BEGIN PUBLIC KEY-----
|
|
2
|
+
${this.getPublicKey()}
|
|
3
|
+
-----END PUBLIC KEY-----`;return I.publicEncrypt({key:t,padding:I.constants.RSA_PKCS1_PADDING},Buffer.from(JSON.stringify(e),"utf8")).toString("base64")}decrypt(e){let t=`-----BEGIN PRIVATE KEY-----
|
|
4
|
+
${this.getPrivateKey()}
|
|
5
|
+
-----END PRIVATE KEY-----`,s=new K(t,"pkcs8",{encryptionScheme:"pkcs1"});s.setOptions({environment:"browser"});let n=s.decrypt(e).toString("utf8");return JSON.parse(n)}sign(e){let t=`-----BEGIN PRIVATE KEY-----
|
|
6
|
+
${this.getPrivateKey()}
|
|
7
|
+
-----END PRIVATE KEY-----`,s=I.createSign("SHA256");return s.update(JSON.stringify(e)),s.end(),s.sign(t,"base64")}confirmPayment(e){return a(this,null,function*(){let t={currencyCode:"050",amount:e.amount,orderId:e.orderId,challenge:e.challenge,merchantId:this.getMerchantId()},s={signature:this.sign(t),paymentRefId:e.paymentReferenceId,sensitiveData:this.encrypt(t),merchantCallbackURL:this.getCallbackUrl(),additionalMerchantInfo:g({},e.productDetails)},[n]=yield this.axios(`${this.getApiBaseUrl()}/check-out/complete/${e.paymentReferenceId}`,{method:"POST",headers:S(g({},this.getApiHeaders()),{"X-KM-IP-V4":e.ip,"X-KM-Client-Type":e.clientType}),body:JSON.stringify(s)});return n})}getCheckoutUrl(e){return a(this,null,function*(){let t=this.getTimeStamp(),s=`${this.getApiBaseUrl()}/check-out/initialize/${this.getMerchantId()}/${e.orderId}`,n={datetime:t,orderId:e.orderId,merchantId:this.getMerchantId(),challenge:this.createHash(e.orderId)},h={dateTime:t,signature:this.sign(n),sensitiveData:this.encrypt(n),accountNumber:this.getMerchantNumber()},[c]=yield this.axios(s,{method:"POST",headers:S(g({},this.getApiHeaders()),{"X-KM-IP-V4":e.ip,"X-KM-Client-Type":e.clientType}),body:JSON.stringify(h)}),p=this.decrypt(c.sensitiveData);return(yield this.confirmPayment({ip:e.ip,challenge:p.challenge,amount:e.amount,orderId:e.orderId,clientType:e.clientType,paymentReferenceId:p.paymentReferenceId,productDetails:e.productDetails})).callBackUrl})}};var A=class extends o{constructor(e){super();this.options=e}getApiBaseUrl(){return this.options.sandbox?"https://api-m.sandbox.paypal.com":"https://api.paypal.com"}getClientId(){return this.options.clientId}getClientSecret(){return this.options.clientSecret}getApiCheckoutUrl(){return`${this.getApiBaseUrl()}/v2/checkout/orders`}getAccessToken(){return a(this,null,function*(){let e=`${this.getApiBaseUrl()}/v1/oauth2/token`,t=btoa(`${this.getClientId()}:${this.getClientSecret()}`),[s]=yield this.jsonFetch(e,{method:"POST",headers:{Authorization:`Basic ${t}`,"Content-Type":"application/x-www-form-urlencoded"},body:"grant_type=client_credentials"});return s.access_token})}getCheckoutUrl(e){return a(this,null,function*(){var h;let t=yield this.getAccessToken(),[s]=yield this.jsonFetch(this.getApiCheckoutUrl(),{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`}}),n=(h=s.links.find(c=>c.rel==="approve"))==null?void 0:h.href;if(!n)throw new Error("Failed to get checkout url");return n})}};var k=class extends o{constructor(e){super();this.options=e}getApiBaseUrl(){return this.options.apiUrl}getApiCheckoutUrl(){return`${this.getApiBaseUrl()}/gwprocess/v4/api.php`}getApiValidationUrl(){return`${this.getApiBaseUrl()}/validator/api/validationserverAPI.php`}getApiRefundUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiRefundQueryUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiTransactionQueryBySessionIdUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiTransactionQueryByTransactionIdUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiHeaders(){return{"Content-Type":"application/x-www-form-urlencoded"}}urlFormEncode(e){return Object.entries(e).map(([t,s])=>`${encodeURIComponent(t)}=${encodeURIComponent(s)}`).join("&")}getCheckoutUrl(e){return a(this,null,function*(){let[t]=yield this.jsonFetch(this.getApiCheckoutUrl(),{method:"POST",body:this.urlFormEncode(e),headers:this.getApiHeaders()});if(t.status==="FAILED")throw new Error(t.failedreason);return t.redirectGatewayURL})}};import{Stripe as x}from"stripe";var f=class{constructor(r,e){this.apiKey=r;this.stripe=new x(r,e)}getCheckoutUrl(r){return a(this,null,function*(){let e=yield this.stripe.checkout.sessions.create(r);if(!e.url)throw new Error("Failed to get checkout url");return e.url})}verifySignature(r){return a(this,null,function*(){try{return{event:yield this.stripe.webhooks.constructEventAsync(r.body,r.signature,r.secret)}}catch(e){return{error:e}}})}};var Se={LemonSqueezy:y,Bkash:l,Paypal:A,SSLCommerz:k,Stripe:f,Nagad:v};export{Se as UnifyPayment};
|
package/package.json
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unify-payment/node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"keywords": [
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
8
|
+
"UnifyPayment",
|
|
9
|
+
"typescript",
|
|
10
|
+
"payment",
|
|
11
|
+
"unified-payment",
|
|
12
|
+
"payment-integration",
|
|
13
|
+
"stripe",
|
|
14
|
+
"lemonsqueezy",
|
|
15
|
+
"payment-gateway",
|
|
16
|
+
"multi-provider",
|
|
17
|
+
"payment-switching",
|
|
18
|
+
"unify-payment",
|
|
19
|
+
"typescript-payment",
|
|
20
|
+
"payment-api",
|
|
21
|
+
"payment-sdk",
|
|
22
|
+
"payment-processor",
|
|
23
|
+
"payment-library",
|
|
24
|
+
"SSLCommerz",
|
|
25
|
+
"Bkash",
|
|
26
|
+
"Nagad"
|
|
19
27
|
],
|
|
20
28
|
"homepage": "https://github.com/shakibhasan09/unify-payment",
|
|
21
29
|
"repository": {
|
|
22
30
|
"url": "https://github.com/shakibhasan09/unify-payment"
|
|
23
31
|
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
24
35
|
"license": "ISC",
|
|
25
36
|
"scripts": {
|
|
26
37
|
"build": "tsup",
|
|
@@ -28,11 +39,15 @@
|
|
|
28
39
|
},
|
|
29
40
|
"devDependencies": {
|
|
30
41
|
"@tsconfig/recommended": "^1.0.7",
|
|
42
|
+
"@types/node-rsa": "^1.1.4",
|
|
31
43
|
"tsup": "^8.2.4",
|
|
32
44
|
"typescript": "^5.4.5"
|
|
33
45
|
},
|
|
34
46
|
"dependencies": {
|
|
35
47
|
"@paddle/paddle-node-sdk": "^1.5.0",
|
|
48
|
+
"axios": "^1.7.6",
|
|
49
|
+
"dayjs": "^1.11.13",
|
|
50
|
+
"node-rsa": "^1.1.1",
|
|
36
51
|
"stripe": "^16.8.0"
|
|
37
52
|
}
|
|
38
53
|
}
|