Skip to content

Commit

Permalink
Merge pull request #110 from VictorKabata/QoL
Browse files Browse the repository at this point in the history
QoL
  • Loading branch information
VictorKabata authored Aug 9, 2024
2 parents 96f72d4 + 4b5c129 commit 9398511
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: unit_tests_report.html
path: daraja/build/reports/tests/testReleaseUnitTest/
path: daraja/build/reports/tests/testDebugUnitTest/
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -178,7 +178,7 @@ darajaMpesaExpressQuery.onSuccess{ mpesaExpressQuery->
}
```

### Generate Dynamic QR Code
<!-- ### Generate Dynamic QR Code
- Generate a dynamic m-pesa qr code
Expand All @@ -197,9 +197,9 @@ darajaQrCode.onSuccess {
}.onFailure {
// Failed to generate a QR code
}
```
``` -->

### Query M-Pesa Transaction
<!-- ### Query M-Pesa Transaction
- To check the status of an M-pesa transaction, invoke the `transactionStatus` function:
Expand All @@ -215,7 +215,7 @@ darajaTransactionResponse
}.onFailure { error ->
// Failure fetching M-pesa transaction status
}
```
``` -->

### Customer To Business(C2B)

Expand Down Expand Up @@ -364,7 +364,7 @@ mpesaExpressQuery.onSuccess(action:{ data in
})
```

### Generate Dynamic QR Code
<!-- ### Generate Dynamic QR Code
- Generate a dynamic m-pesa qr code
Expand All @@ -384,9 +384,9 @@ darajaQrCode.onSuccess(action:{data in
.onFailure(action: {error in
// Failed to generate a QR code
})
```
``` -->

### Query M-Pesa Transaction
<!-- ### Query M-Pesa Transaction
- To check the status of an M-pesa transaction, invoke the `transactionStatus` function:
Expand All @@ -399,9 +399,9 @@ darajaTransactionResponse.onSuccess(action: { data in
}).onFailure(action: { error in
// Failure fetching M-pesa transaction status
})
```
``` -->

### Account Balance
<!-- ### Account Balance
Request the account balance of a short code. This can be used for both B2C, buy goods and pay bill
accounts.
Expand All @@ -421,4 +421,4 @@ accountBalanceResponse.onSuccess(action: { data in
}).onFailure(action: { error in
// Failed to request account balance
})
```
``` -->
12 changes: 6 additions & 6 deletions daraja/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ kotlin {
iosArm64()
iosSimulatorArm64()

jvm()

// js()

cocoapods {
summary = "Daraja API Swift Wrapper built using Kotlin Multiplatform"
homepage = "https://github.com/VictorKabata/DarajaMultiplatform.git"
Expand All @@ -61,6 +57,10 @@ kotlin {
}
}

// jvm()

// js()

sourceSets {
sourceSets["commonMain"].dependencies {
implementation(libs.kotlinX.coroutines)
Expand Down Expand Up @@ -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 {}
Expand Down
24 changes: 13 additions & 11 deletions daraja/src/commonMain/kotlin/com/vickbt/darajakmp/Daraja.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.vickbt.darajakmp.network.models.AccountBalanceResponse
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
Expand Down Expand Up @@ -123,8 +124,9 @@ 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")
)

/**Request access token that is used to authenticate to Daraja APIs
Expand All @@ -139,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.
Expand All @@ -163,7 +165,7 @@ class Daraja(

val darajaPassword = getDarajaPassword(
shortCode = businessShortCode,
passkey = passKey ?: "",
passkey = passKey ?: throw DarajaException(errorMessage = "Pass key is null"),
timestamp = timestamp
)

Expand Down Expand Up @@ -230,7 +232,7 @@ class Daraja(
*
* @return [DynamicQrResponse]
* */
fun generateDynamicQr(
internal fun generateDynamicQr(
merchantName: String,
referenceNumber: String,
amount: Int,
Expand All @@ -252,20 +254,20 @@ class Daraja(

/**Request the status of an Mpesa 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]
* */
@ObjCName(swiftName = "transactionStatus")
fun transactionStatus(
internal fun transactionStatus(
businessShortCode: String,
checkoutRequestID: String
): DarajaResult<DarajaTransactionResponse> = runBlocking(Dispatchers.IO) {
val timestamp = Clock.System.now().getDarajaTimestamp()
val darajaPassword = getDarajaPassword(
shortCode = businessShortCode,
passkey = passKey ?: "",
passkey = passKey ?: throw DarajaException(errorMessage = "Pass key is null"),
timestamp = timestamp
)

Expand All @@ -288,7 +290,7 @@ class Daraja(
*
* @return [C2BResponse]
* */
fun c2bRegistration(
internal fun c2bRegistration(
businessShortCode: Int,
confirmationURL: String,
validationURL: String? = null,
Expand All @@ -304,7 +306,7 @@ class Daraja(
darajaApiService.c2bRegistration(c2bRegistrationRequest = c2BRegistrationRequest)
}

fun c2b(
internal fun c2b(
amount: Int,
billReferenceNumber: String,
transactionType: DarajaTransactionType,
Expand Down Expand Up @@ -335,7 +337,7 @@ class Daraja(
*
* @return [AccountBalanceResponse]
* */
fun accountBalance(
internal fun accountBalance(
initiator: String,
initiatorPassword: String,
commandId: String = "AccountBalance",
Expand Down

0 comments on commit 9398511

Please sign in to comment.