Closed timgithinji closed 3 years ago
@timgithinji this is an internal error on mpesa side, keep trying
Okay, thanks.
{ "requestId":"33908-14618724-1", "errorCode": "500.002.1001", "errorMessage": "Service is currently under maintenance. Please try again later" }
what could be the problem.. try to use daraja api
@OwinoBen that is most likely daraja's API temporary downtime. Happens often, take this into account when doing the integration
@ken-nah thanks
@csrf_exempt @require_http_methods(["POST", "GET"]) def lipa_na_mpesa(request): try: payment = Mpesa_Payments() req = json.loads(request.body.decode("utf-8")) payment.MerchantRequestID = req['Body']['stkCallback']['MerchantRequestID'] payment.CheckoutRequestID = req['Body']['stkCallback']['CheckoutRequestID'] payment.Amount = req['Body']['stkCallback']['CallbackMetadata']['Item'][0]['Value'] payment.MpesaReceiptNumber = req['Body']['stkCallback']['CallbackMetadata']['Item'][1]['Value'] payment.TransactionDate = req['Body']['stkCallback']['CallbackMetadata']['Item'][3]['Value'] payment.PhoneNumber = req['Body']['stkCallback']['CallbackMetadata']['Item'][4]['Value'] payment.save()
order = Order.objects.get(user=request.user, ordered=False)
orderitems = order.cart.all()
orderitems.update(ordered=True)
for item in orderitems:
item.save()
order.ordered = True
order.payment = payment
order.save()
except:
pass
return JsonResponse({})
hello guys. i have a problem with saving the order objecs in the database.. what could be the problem.. this is my mpesa callbackURL function
@OwinoBen are you getting the callback and able to save the payment
object?
@gathuku yes.. problem comes when i want to pass the payment on the order table
is this python? am not familiar with the language but if you are able to save the payment you can debug to check what's happening.
yeah its python.. okay thanks
I don't know how you are getting the order since the callback isn't authenticated and you don't have access to the user.
Maybe you can save save CheckoutRequestID
at the request initiation stage because here you will have access to the user initiation of the request. Then after receiving the call back match the returned CheckoutRequestID
in req['Body']['stkCallback']['CheckoutRequestID']
with the the already saved checkouts. The saved checkouts could also be associated with a certain order.
Sample pseudo code
checkout = OrderCheckout.find_by(checkout_request_id , req['Body']['stkCallback']['CheckoutRequestID'] )
order = checkout.order
order.payment = payment
order.save
@gathuku sorry how do i authenticate the callback?
I don't think you can authenticate a callback, the only thing you can check is if it's coming from the trusted source by checking the request origin IPS
@gathuku good.. let me give it a try bro
I have the following in my
mpesa.php
config fileand in my routes api.php file I'm defining the
/validate
route as follows:and in the MpesaController I'm running the b2c code in your documentation as follows:
but when I run it the response I get is the following error:
Is a part of my configuration wrong or are my urls wrong. I don't understand what's wrong and the error is not explanatory enough. Thanks.