예제 #1
0
        public static LipaNaMpesaResponse From(StkCallback stkCallback)
        {
            var response = new LipaNaMpesaResponse
            {
                MerchantRequestId = stkCallback.MerchantRequestID,
                CheckoutRequestId = stkCallback.CheckoutRequestID
            };

            stkCallback.CallbackMetadata.Item.ForEach(b =>
            {
                if (b.Name == "Amount")
                {
                    response.Amount = (double)b.Value;
                }
                else if (b.Name == "MpesaReceiptNumber")
                {
                    response.ReceiptNumber = (string)b.Value;
                }
                else if (b.Name == "Balance" && b.Value != null)
                {
                    response.Balance = (double)b?.Value;
                }
                else if (b.Name == "TransactionDate")
                {
                    response.TransactionDate = DateTimeOffset.ParseExact(((long)b.Value).ToString(), "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
                }
                else if (b.Name == "PhoneNumber")
                {
                    response.PhoneNumber = ((long)b.Value).ToString();
                }
            });

            return(response);
        }
예제 #2
0
 public static LipaNaMpesaError From(StkCallback stkCallback)
 {
     return(new LipaNaMpesaError
     {
         MerchantRequestId = stkCallback.MerchantRequestID,
         CheckoutRequestId = stkCallback.CheckoutRequestID,
         ErrorCode = stkCallback.ResultCode,
         ErrorMessage = stkCallback.ResultDesc
     });
 }