public async Task <IActionResult> MpesaOnlineTransactionStatus(LipaNaMpesaOnlinePushStkResponse response) { LipaNaMpesaQueryStkResponse queryResult; try { var LipaNaMpesaOnlineQuery = new LipaNaMpesaQuery ( businessShortCode: _mpesaApiConfiguration.LNMOshortCode, passkey: _mpesaApiConfiguration.PassKey, timeStamp: DateTime.Now, checkoutRequestId: response.CheckoutRequestID ); queryResult = await _mpesaClient.QueryLipaNaMpesaTransactionAsync(LipaNaMpesaOnlineQuery, await RetrieveAccessToken(), MpesaRequestEndpoint.QueryLipaNaMpesaOnlineTransaction); } catch (MpesaAPIException ex) { _logger.LogError(ex, ex.Message); return(View().WithDanger("Error", ex.Message)); } var LNMOQueryResponse = queryResult; LNMOQueryResponse.PhoneNumber = response.PhoneNumber; return(RedirectToAction(nameof(MpesaPaymentConfirmation), LNMOQueryResponse)); }
private async Task ExecuteMpesaStkQueryCommand(LipaNaMpesaOnlinePushStkResponse response) { try { var LipaNaMpesaOnlineQuery = new LipaNaMpesaQuery ( businessShortCode: mpesaAPIConfiguration.LNMOshortCode, timeStamp: DateTime.Now, passkey: mpesaAPIConfiguration.PassKey, checkoutRequestId: response.CheckoutRequestID ); var stkQueryResults = await _mpesaClient.QueryLipaNaMpesaTransactionAsync(LipaNaMpesaOnlineQuery, await RetrieveAccessToken(), MpesaRequestEndpoint.QueryLipaNaMpesaOnlineTransaction); if (stkQueryResults.ResultCode.Equals("0")) { Device.BeginInvokeOnMainThread(() => { _dialogs.Alert(new AlertConfig() .SetMessage("Thank you for your payment!") .SetTitle(stkQueryResults.ResponseDescription) .SetAction(async() => await _navigationService.NavigateAsync("/NavigationPage/MpesaPushStkPage"))); }); } else { Device.BeginInvokeOnMainThread(() => { _dialogs.Alert(new AlertConfig() .SetMessage("Something went wrong with the transaction. Please try again") .SetTitle(stkQueryResults.ResponseDescription) .SetAction(async() => await _navigationService.NavigateAsync("/NavigationPage/MpesaPushStkPage"))); }); } } catch (MpesaAPIException ex) { Device.BeginInvokeOnMainThread(() => { _dialogs.Alert(new AlertConfig() .SetMessage(ex.Message.ToString()) .SetTitle(ex.StatusCode.ToString())); }); } catch (Exception ex) { Device.BeginInvokeOnMainThread(() => { _dialogs.Alert(new AlertConfig() .SetMessage(ex.Message.ToString()) .SetTitle("Error")); }); } }
public IActionResult ShowMpesaResult(LipaNaMpesaOnlinePushStkResponse response) { return(View(response)); }