@openfn/language-mpesa 1.0.0

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.
@@ -0,0 +1,241 @@
1
+ /**
2
+ * State object
3
+ * @typedef {Object} HttpState
4
+ * @property data - the parsed response body
5
+ * @property response - the response from the DARAJA API server (excluding the body)
6
+ * @property references - an array of all previous data objects used in the Job
7
+ **/
8
+ /**
9
+ * Options provided to the HTTP request
10
+ * @typedef {Object} RequestOptions
11
+ * @public
12
+ * @property {object} errors - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors for this code.
13
+ * @property {object} query - An object of query parameters to be encoded into the URL.
14
+ * @property {object} headers - An object of headers to append to the request.
15
+ */
16
+ /**
17
+ * STKPush request data object
18
+ * @typedef {Object} STKPushObject
19
+ * @public
20
+ * @property {number} Amount - Amount charged.
21
+ * @property {number} PartyA - The phone number that receives the STK push prompt. Expected to be a valid Safaricom Number that is M-pesa registered in the format 2547XXXXXXXX
22
+ * @property {number} PartyB - The organization that receives the funds
23
+ * @property {number} PhoneNumber - The mobile number to receive the STK pin prompt
24
+ * @property {URL} CallBackURL - A valid secure URL that is used to receive notifications from M-Pesa API. It is the endpoint to which the results will be sent by M-Pesa API
25
+ * @property {string} AccountReference - Along with the business name, this value is also displayed to the customer in the STK pin prompt message. Maximum of 12 characters
26
+ * @property {string} TransactionDesc - Any additional information/comment that can be sent along with the request from you system.
27
+ */
28
+ /**
29
+ * Initiate a STK pin prompt to a Safaricom mobile number.
30
+ * @function
31
+ * @public
32
+ * @param {STKPushObject} data - The object that will be attached to the POST request body
33
+ * @param {RequestOptions} options - Optional request object. Includes headers, error mappings and query params
34
+ * @example <caption>Initiate STK Push</caption>
35
+ * stkPush({
36
+ "Amount": 1,
37
+ "PartyA": 254708374149,
38
+ "PartyB": 174379,
39
+ "PhoneNumber": 254708374149,
40
+ "CallBackURL": "https://mydomain.com/path",
41
+ "AccountReference": "CompanyXLTD",
42
+ "TransactionDesc": "Payment of X"
43
+ });
44
+ * @returns {Operation}
45
+ * @state {HttpState}
46
+ */
47
+ export function stkPush(data: STKPushObject, options?: RequestOptions): Operation;
48
+ /**
49
+ * Check transaction status data object.
50
+ * @typedef {Object} TransactionStatusObject
51
+ * @public
52
+ * @property {string} Initiator - The name of the initiator initiating the request.
53
+ * @property {string} SecurityCredential - Encrypted credential of the user getting transaction status.
54
+ * @property {string} TransactionID - Unique identifier to identify a transaction on Mpesa.
55
+ * @property {number} PartyA - Organization/MSISDN receiving the transaction.
56
+ * @property {number} IdentifierType - Type of organization receiving the transaction. Example: "4" Orgnaization shortcode.
57
+ * @property {URL} ResultURL - The path that stores information of a transaction.
58
+ * @property {URL} QueueTimeOutURL - The path that stores information of timeout transaction.
59
+ * @property {string} Remarks - Comments that are sent along with the transaction.
60
+ * @property {string} Occassion - Optional parameter.
61
+ */
62
+ /**
63
+ * Check the status of the transaction
64
+ * @function
65
+ * @public
66
+ * @param {TransactionStatusObject} data - The object that will be attached to the POST request body
67
+ * @param {RequestOptions} options - Optional request object. Includes headers, error mappings and query params
68
+ * @example <caption>Check status of a transaction</caption>
69
+ * checkTransactionStatus({
70
+ "Initiator": "testapi",
71
+ "SecurityCredential": "ctHDk+dN14A22B5GyQQvISSTY3K1tVnCTuQGoG7PsTCadzTkl5wz44Rhpkb0BZDvfRA==",
72
+ "TransactionID": "OEI2AK4Q16",
73
+ "PartyA": 600998,
74
+ "IdentifierType": 4,
75
+ "ResultURL": "https://mydomain.com/TransactionStatus/result/",
76
+ "QueueTimeOutURL": "https://mydomain.com/TransactionStatus/queue/",
77
+ "Remarks": "fdfdfdfdf",
78
+ "Occassion": "null",
79
+ });
80
+ * @returns {Operation}
81
+ * @state {HttpState}
82
+ */
83
+ export function checkTransactionStatus(data: TransactionStatusObject, options?: RequestOptions): Operation;
84
+ /**
85
+ * Register URL parameter definition
86
+ * @typedef {Object} RegisterUrlObject
87
+ * @public
88
+ * @property {numeric} ShortCode - Usually, a unique number is tagged to an M-PESA pay bill/till number of the organization.
89
+ * @property {string} ResponseType - This parameter specifies what is to happen if for any reason the validation URL is not reachable. Sample values: 'Canceled', 'Completed'
90
+ * @property {URL} ConfirmationURL - This is the URL that receives the confirmation request from API upon payment completion.
91
+ * @property {URL} ValidationURL - This is the URL that receives the validation request from the API upon payment submission.
92
+ */
93
+ /**
94
+ * Register a URL that allows receiving payment notifications to your paybill.
95
+ * @public
96
+ * @function
97
+ * @param {RegisterUrlObject} data - The object that will be attached to the POST request body
98
+ * @param {RequestOptions} options - Optional request object. Includes headers, error mappings and query params
99
+ * @example <caption>Register a URL to receive payment notifications</caption>
100
+ * registerUrl({
101
+ "ShortCode": 600426,
102
+ "ResponseType": "Completed",
103
+ "ConfirmationURL": "https://mydomain.com/confirmation",
104
+ "ValidationURL": "https://mydomain.com/validation"
105
+ });
106
+ * @returns {Operation}
107
+ * @state {HttpState}
108
+ */
109
+ export function registerUrl(data: RegisterUrlObject, options: RequestOptions): Operation;
110
+ /**
111
+ * Remit tax parameter definition
112
+ * @typedef {Object} RemitTaxObject
113
+ * @public
114
+ * @property {string} Initiator - The M-Pesa API operator username.
115
+ * @property {string} SecurityCredential - The encrypted password of the M-Pesa API operator.
116
+ * @property {number} Amount - The transaction amount.
117
+ * @property {number} PartyA - This is your own shortcode from which the money will be deducted.
118
+ * @property {string} AccountReference - The payment registration number (PRN) issued by KRA.
119
+ * @property {string} Remarks - Any additional information to be associated with the transaction.
120
+ * @property {URL} QueueTimeOutURL - A URL that will be used to notify your system in case the request times out before processing.
121
+ * @property {URL} ResultURL - A URL that will be used to send transaction results after processing.
122
+ */
123
+ /**
124
+ * Remit tax to the Kenya Revenue Authority (KRA).
125
+ * @public
126
+ * @function
127
+ * @param {RemitTaxObject} data - The object that will be attached to the POST request body
128
+ * @param {RequestOptions} options - Optional request object. Includes headers, error mappings and query params
129
+ * @example <caption>Pay tax to KRA</caption>
130
+ * remitTax({
131
+ "Initiator": "testapi",
132
+ "SecurityCredential": "Uq1qluCjSYfMF3XEvlpfuatnWwWerwq42fB+mMd8nsKdAVO04DGHhG/s3xO3g7POki9B8i7cSoEkBux4bQrlDLDWJhaTrt1TdbE+ZQ==",
133
+ "Amount": 1,
134
+ "PartyA": 600995,
135
+ "AccountReference": 353353,
136
+ "Remarks": "ok",
137
+ "QueueTimeOutURL": "https://mydomain.com/b2b/queue/",
138
+ "ResultURL": "https://mydomain.com/b2b/result/"
139
+ })
140
+ * @returns {Operation}
141
+ * @state {HttpState}
142
+ */
143
+ export function remitTax(data: RemitTaxObject, options?: RequestOptions): Operation;
144
+ /**
145
+ * Buy goods parameter definition
146
+ * @typedef {Object} BuyGoodsObject
147
+ * @public
148
+ * @property {string} Initiator - The M-Pesa API operator username. This user needs Org Business Pay Bill API initiator role on M-Pesa
149
+ * @property {string} SecurityCredential - The encrypted password of the M-Pesa API operator.
150
+ * @property {number} Amount - The transaction amount.
151
+ * @property {number} PartyA - Your shortcode. The shortcode from which money will be deducted.
152
+ * @property {string} AccountReference - The account number to be associated with the payment. Up to 13 characters
153
+ * @property {string} Remarks - Any additional information to be associated with the transaction.
154
+ * @property {URL} QueueTimeOutURL - A URL that will be used to notify your system in case the request times out before processing.
155
+ * @property {URL} ResultURL - A URL that will be used to send transaction results after processing.
156
+ */
157
+ /**
158
+ * Pay for goods and services directly from your business account to a till number, merchant store number or Merchant HO
159
+ * @function
160
+ * @public
161
+ * @param {BuyGoodsObject} data - The object that will be attached to the POST request body
162
+ * @param {RequestOptions} options - Optional request object. Includes headers, error mappings and query params
163
+ * @example <caption>Pay for goods</caption>
164
+ * buyGoods({
165
+ "Initiator": "testapi",
166
+ "SecurityCredential": "sbMXpuhMX5LzieNiDrx9TgscfaBxxvie0WlBDdGli4MWu4s5gbhYVlBy+T89xHQdoYwcG202KNp403ln2dLFnytPqw==",
167
+ "Amount": 1,
168
+ "PartyA": 600999,
169
+ "PartyB": 600000,
170
+ "AccountReference": 353353,
171
+ "Requester": 254708374149,
172
+ "Remarks": "ok",
173
+ "QueueTimeOutURL": "https://mydomain.com/b2b/queue/",
174
+ "ResultURL": "https://mydomain.com/b2b/result/"
175
+ });
176
+ * @returns {Operation}
177
+ * @state {HttpState}
178
+ */
179
+ export function buyGoods(data: BuyGoodsObject, options?: RequestOptions): Operation;
180
+ /**
181
+ * Make a general HTTP request
182
+ * @example <caption>Register a URL to receive payment notifications</caption>
183
+ * request("POST", "/mpesa/c2b/v1/registerurl",
184
+ * {
185
+ * "ShortCode": 600426,
186
+ * "ResponseType": "Completed",
187
+ * "ConfirmationURL": "https://mydomain.com/confirmation",
188
+ * "ValidationURL": "https://mydomain.com/validation"
189
+ * });
190
+ * @function
191
+ * @public
192
+ * @param {string} method - HTTP method to use
193
+ * @param {string} path - Path to resource.
194
+ * @param {object} body - Object which will be attached to the POST body
195
+ * @param {RequestOptions} options - Optional request options
196
+ * @returns {Operation}
197
+ * @state {HttpState}
198
+ */
199
+ export function request(method: string, path: string, body: object, options?: RequestOptions): Operation;
200
+ /**
201
+ * State object
202
+ */
203
+ export type HttpState = {
204
+ /**
205
+ * - the parsed response body
206
+ */
207
+ data: any;
208
+ /**
209
+ * - the response from the DARAJA API server (excluding the body)
210
+ */
211
+ response: any;
212
+ /**
213
+ * - an array of all previous data objects used in the Job
214
+ */
215
+ references: any;
216
+ };
217
+ /**
218
+ * Options provided to the HTTP request
219
+ */
220
+ export type RequestOptions = any;
221
+ /**
222
+ * STKPush request data object
223
+ */
224
+ export type STKPushObject = any;
225
+ /**
226
+ * Check transaction status data object.
227
+ */
228
+ export type TransactionStatusObject = any;
229
+ /**
230
+ * Register URL parameter definition
231
+ */
232
+ export type RegisterUrlObject = any;
233
+ /**
234
+ * Remit tax parameter definition
235
+ */
236
+ export type RemitTaxObject = any;
237
+ /**
238
+ * Buy goods parameter definition
239
+ */
240
+ export type BuyGoodsObject = any;
241
+ export { dataPath, dataValue, dateFns, cursor, each, field, fields, fn, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
@@ -0,0 +1,4 @@
1
+ export function prepareNextState(state: any, response: any): any;
2
+ export function getTimestamp(): string;
3
+ export function getAccessToken(configuration: any): Promise<any>;
4
+ export function request(state: any, method: any, path: any, options: any): Promise<any>;
@@ -0,0 +1,3 @@
1
+ export default Adaptor;
2
+ export * from "./Adaptor";
3
+ import * as Adaptor from "./Adaptor";