From 1b000f339dae51f72bccd6cd4096220649a08baf Mon Sep 17 00:00:00 2001 From: Victor Kabata Date: Fri, 9 Aug 2024 15:55:44 +0300 Subject: [PATCH 1/4] Throw exception when consumer key or secret and passkey are null --- .github/workflows/build.yml | 2 +- daraja/build.gradle.kts | 6 +++--- .../kotlin/com/vickbt/darajakmp/Daraja.kt | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f2468858..b20f3424 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,4 +50,4 @@ jobs: uses: actions/upload-artifact@v3 with: name: unit_tests_report.html - path: daraja/build/reports/tests/testReleaseUnitTest/ \ No newline at end of file + path: daraja/build/reports/tests/testDebugUnitTest/ \ No newline at end of file diff --git a/daraja/build.gradle.kts b/daraja/build.gradle.kts index f5e9dcda..9925f033 100644 --- a/daraja/build.gradle.kts +++ b/daraja/build.gradle.kts @@ -57,7 +57,7 @@ kotlin { } } - jvm() + // jvm() // js() @@ -93,10 +93,10 @@ kotlin { } sourceSets["iosTest"].dependencies {} - sourceSets["jvmMain"].dependencies { + /*sourceSets["jvmMain"].dependencies { implementation(libs.ktor.java) } - sourceSets["jvmTest"].dependencies {} + sourceSets["jvmTest"].dependencies {}*/ // sourceSets["jsMain"].dependencies {} // sourceSets["jsTest"].dependencies {} diff --git a/daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt b/daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt index 9374a5ed..cdd6083c 100644 --- a/daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt +++ b/daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt @@ -21,6 +21,7 @@ import com.vickbt.darajakmp.network.DarajaHttpClientFactory import com.vickbt.darajakmp.network.models.C2BRegistrationRequest import com.vickbt.darajakmp.network.models.C2BRequest import com.vickbt.darajakmp.network.models.C2BResponse +import com.vickbt.darajakmp.network.models.DarajaException import com.vickbt.darajakmp.network.models.DarajaToken import com.vickbt.darajakmp.network.models.DarajaTransactionRequest import com.vickbt.darajakmp.network.models.DarajaTransactionResponse @@ -115,12 +116,11 @@ class Daraja( /**Create instance of [DarajaApiService]*/ private val darajaApiService: DarajaApiService = DarajaApiService( httpClient = darajaHttpClientFactory, - consumerKey = consumerKey ?: "", - consumerSecret = consumerSecret ?: "" + consumerKey = consumerKey ?: throw DarajaException(errorMessage = "Consumer key is null"), + consumerSecret = consumerSecret + ?: throw DarajaException(errorMessage = "Consumer secret is null") ) - private val ioCoroutineContext = CoroutineScope(Dispatchers.IO).coroutineContext - /**Request access token that is used to authenticate to Daraja APIs * * @return [DarajaToken] @@ -157,7 +157,7 @@ class Daraja( val darajaPassword = getDarajaPassword( shortCode = businessShortCode, - passkey = passKey ?: "", + passkey = passKey ?: throw DarajaException(errorMessage = "Pass key is null"), timestamp = timestamp ) @@ -178,9 +178,9 @@ class Daraja( darajaApiService.initiateMpesaExpress(mpesaExpressRequest = mpesaExpressRequest) } - /**Request the status of an Mpesa payment transaction + /**Request the status of an M-Pesa payment transaction * - * @param [businessShortCode] This is organizations shortcode (Paybill or Buygoods - A 5 to 7 digit account number) used to identify an organization and receive the transaction. + * @param [businessShortCode] This is organizations shortcode (Paybill or Buy Goods - A 5 to 7 digit account number) used to identify an organization and receive the transaction. * @param [checkoutRequestID] This is a global unique identifier of the processed checkout transaction request. * * @return [DarajaTransactionResponse] @@ -193,7 +193,7 @@ class Daraja( val timestamp = Clock.System.now().getDarajaTimestamp() val darajaPassword = getDarajaPassword( shortCode = businessShortCode, - passkey = passKey ?: "", + passkey = passKey ?: throw DarajaException(errorMessage = "Pass key is null"), timestamp = timestamp ) From e2d30a4f53d8a3acd8c9dff2573e048f3b31aa43 Mon Sep 17 00:00:00 2001 From: Victor Kabata Date: Fri, 9 Aug 2024 16:40:02 +0300 Subject: [PATCH 2/4] Removed unstable apis from public access --- .../commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt b/daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt index fad00997..507bb3c5 100644 --- a/daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt +++ b/daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt @@ -232,7 +232,7 @@ class Daraja( * * @return [DynamicQrResponse] * */ - fun generateDynamicQr( + internal fun generateDynamicQr( merchantName: String, referenceNumber: String, amount: Int, @@ -260,7 +260,7 @@ class Daraja( * @return [DarajaTransactionResponse] * */ @ObjCName(swiftName = "transactionStatus") - fun transactionStatus( + internal fun transactionStatus( businessShortCode: String, checkoutRequestID: String ): DarajaResult = runBlocking(Dispatchers.IO) { @@ -290,7 +290,7 @@ class Daraja( * * @return [C2BResponse] * */ - fun c2bRegistration( + internal fun c2bRegistration( businessShortCode: Int, confirmationURL: String, validationURL: String? = null, @@ -306,7 +306,7 @@ class Daraja( darajaApiService.c2bRegistration(c2bRegistrationRequest = c2BRegistrationRequest) } - fun c2b( + internal fun c2b( amount: Int, billReferenceNumber: String, transactionType: DarajaTransactionType, @@ -337,7 +337,7 @@ class Daraja( * * @return [AccountBalanceResponse] * */ - fun accountBalance( + internal fun accountBalance( initiator: String, initiatorPassword: String, commandId: String = "AccountBalance", From 679f035cef409895ffc270a6c5d499a908ebc729 Mon Sep 17 00:00:00 2001 From: Victor Kabata Date: Fri, 9 Aug 2024 17:13:21 +0300 Subject: [PATCH 3/4] Linting --- daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt b/daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt index 507bb3c5..27ab3a54 100644 --- a/daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt +++ b/daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt @@ -141,7 +141,7 @@ class Daraja( /**Initiate Mpesa Express payment of value provided in [amount] to the [businessShortCode] from the the [phoneNumber]. * The response of the payment status will be sent to the [callbackUrl] provided. * - * @param [businessShortCode] This is organizations shortcode (Paybill or Buygoods - A 5 to 7 digit account number) used to identify an organization and receive the transaction. + * @param [businessShortCode] This is organizations shortcode (Paybill or Buy Goods - A 5 to 7 digit account number) used to identify an organization and receive the transaction. * @param [amount] Money that customer pays to the [businessShortCode] * @param [phoneNumber] The mobile number to receive the STK pin prompt. * @param [transactionType] This is the transaction type that is used to identify the transaction when sending the request to M-Pesa. From 4b5c1295f8bb378f90c60c50a3c903d3f946ab59 Mon Sep 17 00:00:00 2001 From: Victor Kabata Date: Fri, 9 Aug 2024 17:18:26 +0300 Subject: [PATCH 4/4] Update README.md --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b5241066..14940062 100644 --- a/README.md +++ b/README.md @@ -54,12 +54,12 @@ The SDK offers the following functionalities from the Daraja API: - [x] Authorization - Gives you a time bound access token to call allowed APIs. - [x] M-Pesa Express - Merchant initiated online payments. - [x] M-Pesa Express Query - Check the status of a Lipa Na M-Pesa Online Payment(M-Pesa Express). -- [x] Dynamic QR - Generates a dynamic M-PESA QR code. -- [x] Customer To Business (C2B) +- [ ] Dynamic QR - Generates a dynamic M-PESA QR code. +- [ ] Customer To Business (C2B) - [ ] Business To Customer (B2C) - Transact between an M-Pesa short code to a phone number registered on M-Pesa. -- [x] Transaction Status - Check the status of a transaction. -- [x] Account Balance - Enquire the balance on an M-Pesa BuyGoods (Till Number) +- [ ] Transaction Status - Check the status of a transaction. +- [ ] Account Balance - Enquire the balance on an M-Pesa BuyGoods (Till Number) - [ ] Reversal - Reverses an M-Pesa transaction. - [ ] Tax Remittance - This API enables businesses to remit tax to Kenya Revenue Authority (KRA). - [ ] Business Pay Bill - Pay bills directly from your business account to a pay bill number, or a @@ -178,7 +178,7 @@ darajaMpesaExpressQuery.onSuccess{ mpesaExpressQuery-> } ``` -### Generate Dynamic QR Code + -### Query M-Pesa Transaction + ### Customer To Business(C2B) @@ -364,7 +364,7 @@ mpesaExpressQuery.onSuccess(action:{ data in }) ``` -### Generate Dynamic QR Code + -### Query M-Pesa Transaction + -### Account Balance + \ No newline at end of file