UNPKG

palmpaywrappersdk

Version:

PalmPay Wrapper Sdk

97 lines (96 loc) 6.54 kB
"use strict"; 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 }); exports.CreateOrderService = void 0; const axios_1 = __importDefault(require("axios")); const CreateOrderRequest_1 = require("../RequestDTOs/CreateOrderRequest"); const CreateOrderRequestBuilder_1 = require("../RequestDTOs/CreateOrderRequestBuilder"); //import { sign } from '../RequestDTOs/SignUtil'; const SignUtil_1 = require("../RequestDTOs/SignUtil"); const VerifyUtil_1 = require("../RequestDTOs/VerifyUtil"); const CREATE_ORDER_API_URL = 'https://open-gw-daily.palmpay-inc.com/api/v2/payment/merchant/createorder'; class CreateOrderService { constructor() { this.headers = { // 'Signature': 'itPnz2ybR6MWWt4ghYuxECUT3nYSdmkGjXLmRJRJaBJYeamLRHohYK7Z4pRSZwP3VM8ztL//FxQvnDnSm/76xHOIB1rkTGhVeM/8aRWR7/Kj2BCi6fi2SX/OioFl3O03slp1bFZ6ualV1/Sq9ajkbXTT0jlmQ2ket/z4oRgwb32UMJP47exgJe2zONx+uOSDcnlSSx+oLHwa+BFk2Bz+NB151J70TCw+JkNLqUHu+8imQ4DyjXKtE1WnEHB6S+eRwDbMw6s5yzwza5Go+H2oC6/PpwG8OBCF4hNNEenCoDrarlaqiWxDiYQ9QUgXh+NpbqJRTILnUJNZRmf7b/27yA==', 'Signature': 'WgFZDZbuknHywGef4hXwCsNLp4pqNzrrXFTlhuxjFWnZXLKGBrFgkP+uBr0aho0JuwQXo4i+M8oU98cJ3qp/BN0BxM4lnXNS1lzn64Iywpu5fUC/sL45l28CkDSvRfLcJNvxq+2DM7+I6YnspPhPiyQc/6keC2lnSyY8DyikAxY=', 'Authorization': 'Bearer L39255713352', 'countryCode': 'NG', 'Content-Type': 'application/json' }; this.createOrderRequest = new CreateOrderRequestBuilder_1.CreateOrderRequestBuilder(1662171389940, 'V1.1', 'IBJGAeTa4ZJQv4Z2qufomVo9eI1YnJ9Y') .withAmount(2000) .withNotifyUrl('https://webhook.site/9d6d3115-bacf-46d0-9724-716c205e074e') .withOrderId('testc9ddae997f78') .withTitle('pay') .withDescription('pay some thing') .withUserId('110') .withUserMobileNo('07011698742') .withCurrency('NGN') .withCallBackUrl('http://returnurls') .withGoodsDetails('[{"goodsId": "1"}]') .withProductType('pay_with_code') .build(); } createCreateOrderRequest() { return new CreateOrderRequest_1.CreateOrderRequest(1662171389940, 'V1.1', 'IBJGAeTa4ZJQv4Z2qufomVo9eI1YnJ9Y', 200, 'https://webhook.site/9d6d3115-bacf-46d0-9724-716c205e074e', 'testc9ddae997f78', 'pay', 'pay some thing', '110', '07011698742', 'NGN', 'http://returnurl', '[{"goodsId": "1"}]', 'pay_wallet'); } createOrderRequestBuilder() { return new CreateOrderRequestBuilder_1.CreateOrderRequestBuilder(1662171389940, 'V1.1', 'IBJGAeTa4ZJQv4Z2qufomVo9eI1YnJ9Y') .withAmount(2000) .withNotifyUrl('https://webhook.site/9d6d3115-bacf-46d0-9724-716c205e074e') .withOrderId('testc9ddae997f78') .withTitle('pay') .withDescription('pay some thing') .withUserId('110') .withUserMobileNo('07011698742') .withCurrency('NGN') .withCallBackUrl('http://returnurls') .withGoodsDetails('[{"goodsId": "1"}]') .withProductType('pay_with_code') .build(); } createSign() { return __awaiter(this, void 0, void 0, function* () { const privateKey = 'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAICK1MVSH/1bR1ghWfzlXl2v/wVkLhwZT9CfzwFVE5VwifdKBRzSi5GjeZqM9vcuC7bZrpkI2IKhXH9QbzPWHgP1eeCCwTDp6esKux6LWpT60DKvYGIrAGBFCM8WMS24d2luOaB6BTEJS7WBN0j81cJGzNqdsfB1nnnr8J4T/euXAgMBAAECgYB7X0RqArGrZNFr98672JWizAmzbfyHgY/Gh6uR9sruEm6IxyVzDW1hogpT2NosUahynilivke30RHLLDMfCHITNFkTmxIMH0uaBfWPM8xRCL4Jq4hJKsvMZhVxvVK8SxKjElawhlswBt5xBcuT/i5GasBvIiNw6Gr7gV7OIJN2CQJBALl/s8FvKkmgQ2AwQzfbx0Q5M89Yx/qfY2vgMJkpVnNrgmcRKhXZFFoQwqPCvRcW4Ij2QTwiqZuF09QDFTXPIWUCQQCxZXxZbxJnKfUV2tZnefLpag7sp5hJuvbGx5oRx22oKzxl5NA3tLVH10xFeZ5Qjf72luKxl3ghdlNiPy/QKedLAkEAknEIXdr+zWUiC5vOVRjCdU+bYUO7jFWsTYuNkjyaLUBgkDFywhDACmJU5qdkVAgRds7BrVHICClck3FjmzlMKQJAMaX7pXQmrGTbySAUPaWtzJH4V1eYkZoYEw4uGqe8EwL2xnXBqLWUvuSM3izpmBYFs7ILBDUmVAcv0yFoGlR//QJACMBGCaNr6e3JmGTo8HJRmPpdOJlJPISLYxHlXhDtUs+UuYzZrnU4SEQUnflmUijTDX4FXxm2TX4gm+6OTUkkHg=='; const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCAitTFUh/9W0dYIVn85V5dr/8FZC4cGU/Qn88BVROVcIn3SgUc0ouRo3majPb3Lgu22a6ZCNiCoVx/UG8z1h4D9XnggsEw6enrCrsei1qU+tAyr2BiKwBgRQjPFjEtuHdpbjmgegUxCUu1gTdI/NXCRszanbHwdZ556/CeE/3rlwIDAQAB'; console.log('Builder Request: ', this.createOrderRequest); const signedRequest = (0, SignUtil_1.sign)(this.createOrderRequest.toJSON(), privateKey); console.log('Signed Request:', signedRequest); const verifiedRequest = VerifyUtil_1.VerifyUtil.verify(this.createOrderRequest.toJSON(), signedRequest, publicKey); console.log('Verified Request:', verifiedRequest); }); } createOrder() { return __awaiter(this, void 0, void 0, function* () { const createOrderRequest = this.createOrderRequestBuilder(); console.log('OrderStatusRequest JSON:', JSON.stringify(createOrderRequest.toJSON(), null, 2)); console.log('The Headers:', this.headers); console.log('The Post Url: ', CREATE_ORDER_API_URL); try { const response = yield axios_1.default.post(CREATE_ORDER_API_URL, createOrderRequest.toJSON(), { headers: this.headers }); return response.data; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`Error message: ${error.message}`); } else { throw new Error('Unexpected error'); } } }); } } exports.CreateOrderService = CreateOrderService;