-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update docs and extract constant types
- Loading branch information
Showing
5 changed files
with
193 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/jwambugu/mpesa-golang-sdk" | ||
"log" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
func main() { | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
|
||
mpesaApp := mpesa.NewApp(http.DefaultClient, "CONSUMER_KEY", "CONSUMER_SECRET", mpesa.EnvironmentSandbox) | ||
|
||
stkResp, err := mpesaApp.STKPush(ctx, "YOUR_PASSKEY", mpesa.STKPushRequest{ | ||
BusinessShortCode: 174379, | ||
TransactionType: mpesa.CustomerPayBillOnlineTransactionType, | ||
Amount: 10, | ||
PartyA: 254708374149, | ||
PartyB: 174379, | ||
PhoneNumber: 254708374149, | ||
CallBackURL: "https://webhook.site/62daf156-31dc-4b07-ac41-698dbfadaa4b", | ||
AccountReference: "Test reference", | ||
TransactionDesc: "Test description", | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("stk: %v\n", err) | ||
} | ||
|
||
log.Printf("stk: %+v\n", stkResp) | ||
|
||
stkQueryRes, err := mpesaApp.STKQuery(ctx, "YOUR_PASSKEY", mpesa.STKQueryRequest{ | ||
BusinessShortCode: 174379, | ||
CheckoutRequestID: "ws_CO_260520211133524545", | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("stk query: %v\n", err) | ||
} | ||
|
||
log.Printf("stk query %+v\n", stkQueryRes) | ||
|
||
txnStatusRes, err := mpesaApp.GetTransactionStatus(ctx, "Safaricom999!*!", mpesa.TransactionStatusRequest{ | ||
IdentifierType: mpesa.ShortcodeIdentifierType, | ||
Initiator: "YOUR_INITIATOR_NAME", | ||
Occasion: "Test occassion", | ||
OriginatorConversationID: "", | ||
PartyA: 600426, | ||
QueueTimeOutURL: "https://webhook.site/62daf156-31dc-4b07-ac41-698dbfadaa4b", | ||
Remarks: "Test remarks", | ||
ResultURL: "https://webhook.site/62daf156-31dc-4b07-ac41-698dbfadaa4b", | ||
TransactionID: "SB162HIYLY", | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("txn status: %v\n", err) | ||
} | ||
|
||
log.Printf("txn status: %+v\n", txnStatusRes) | ||
|
||
b2cRes, err := mpesaApp.B2C(ctx, "Safaricom999!*!", mpesa.B2CRequest{ | ||
InitiatorName: "YOUR_INITIATOR_NAME", | ||
CommandID: mpesa.BusinessPaymentCommandID, | ||
Amount: 10, | ||
PartyA: 600426, | ||
PartyB: 254708374149, | ||
Remarks: "This is a remark", | ||
QueueTimeOutURL: "https://webhook.site/62daf156-31dc-4b07-ac41-698dbfadaa4b", | ||
ResultURL: "https://webhook.site/62daf156-31dc-4b07-ac41-698dbfadaa4b", | ||
Occasion: "Test Occasion", | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("b2c: %v\n", err) | ||
} | ||
|
||
log.Printf("b2c: %+v\n", b2cRes) | ||
|
||
accBal, err := mpesaApp.GetAccountBalance(ctx, "Safaricom999!*!", mpesa.AccountBalanceRequest{ | ||
Initiator: "YOUR_INITIATOR_NAME", | ||
PartyA: 600981, | ||
QueueTimeOutURL: "https://webhook.site/62daf156-31dc-4b07-ac41-698dbfadaa4b", | ||
Remarks: "Test Local", | ||
ResultURL: "https://webhook.site/62daf156-31dc-4b07-ac41-698dbfadaa4b", | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("account balance: %v\n", err) | ||
} | ||
|
||
log.Printf("account balance: %+v\n", accBal) | ||
} |
Oops, something went wrong.