/// <summary> /// Post a request to pay /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <ClientResponse <string> > PostRequestToPay(PostReqesutToPayRequest request, string callbackUrl = null) { var token = await GetToken(); if (string.IsNullOrEmpty(token?.AccessToken)) { return(new ClientResponse <string> { Status = Status.Failed.ToString(), StatusCode = HttpStatusCode.Unauthorized }); } var paymentReference = Guid.NewGuid().ToString(); var headers = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(Constants.PaymentReferenceHeader, $"{paymentReference}"), new KeyValuePair <string, string>(Constants.AuthHeader, $"Bearer {token.AccessToken}"), new KeyValuePair <string, string>(Constants.SubKeyHeader, collectionConfig.SubscriptionKey) }; if (!string.IsNullOrEmpty(callbackUrl)) { headers.Add(new KeyValuePair <string, string>(Constants.CallbackUrlHeader, callbackUrl)); } var response = await baseClient.PostAsync <string>(CollectionRequestUri.RequestToPay, Constants.MtnClient, request, headers); response.Data = response.StatusCode == HttpStatusCode.Accepted ? paymentReference : null; response.Status = response.StatusCode == HttpStatusCode.Accepted ? Status.Successful.ToString() : Status.Failed.ToString(); return(response); }
public async Task <IActionResult> Collection() { /** * Sample test data when Collection client used */ var model = new PostReqesutToPayRequest { Amount = "20", Currency = "EUR", ExternalId = "222", Payer = new Payer { PartyId = "0557143133", PartyIdType = PartyIdType.MSISDN }, PayerMessage = "test", PayeeNote = "test" }; var postrequestResult = await collectionClient.PostRequestToPay(model); var getrequestResult = await collectionClient.GetRequestToPay(postrequestResult.Data); return(Ok(new { post = postrequestResult, get = getrequestResult })); }
public void Test_Mtn_Collection_Api_RequestToPay() { //make a transfer var model = new PostReqesutToPayRequest { Amount = "20", Currency = "EUR", ExternalId = "222", Payer = new Payer { PartyId = "0557143133", PartyIdType = PartyIdType.MSISDN }, PayerMessage = "test", PayeeNote = "test" }; var postrequestResult = collectionClient.PostRequestToPay(model).Result; postrequestResult.Data.Should().NotBeNull(); postrequestResult.Status.Should().Be("Successful"); postrequestResult.StatusCode.Should().Be(HttpStatusCode.Accepted); //get a transfer var getrequestResult = collectionClient.GetRequestToPay(postrequestResult.Data).Result; getrequestResult.Data.Amount.Should().Be("20"); getrequestResult.Data.Currency.Should().Be("EUR"); getrequestResult.Status.Should().Be("Successful"); getrequestResult.StatusCode.Should().Be(HttpStatusCode.OK); }