Created
March 28, 2017 13:52
-
-
Save makafanpeter/c28fa694df68be7d8f6c66199446d10b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public override void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest) | |
{ | |
var url = string.Format("{0}", GetSpriteUrl()); | |
try | |
{ | |
var request = new HttpClient() | |
{ | |
BaseAddress = new Uri(url) | |
}; | |
request.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |
request.DefaultRequestHeaders.Add("apikey", _ebipsReverseNeftSettings.SpriteApiKey); | |
request.DefaultRequestHeaders.Add("apicode", _ebipsReverseNeftSettings.SpriteApiCode); | |
_logger.Information(string.Format("Sprite Requery Request {0}", postProcessPaymentRequest.Settlement.AuthorizationTransactionId)); | |
//Try to query payment | |
var response = request.GetAsync(string.Format("api/ReverseNeft/Requery?NEFTReference={0}",postProcessPaymentRequest.Settlement.AuthorizationTransactionId)).Result; | |
if (response.StatusCode == HttpStatusCode.OK) | |
{ | |
var ebipsResponse = response.Content.ReadAsAsync<List<EbipsRequeryResponse>>().Result; | |
if (ebipsResponse != null) | |
{ | |
if (ebipsResponse.Any(t=>t.NibssResponse== "File completely received")) | |
{ | |
postProcessPaymentRequest.Settlement.PaymentStatus = PaymentStatus.Swept; | |
} | |
} | |
var jsonRequest = JsonConvert.SerializeObject(ebipsResponse); | |
_logger.Information(string.Format("Sprite JSON Response {0} ,Settlement {1}", jsonRequest, postProcessPaymentRequest.Settlement.AuthorizationTransactionId)); | |
} | |
//if the transaction hasnt been pushed try to reprocess | |
else if (response.StatusCode == HttpStatusCode.NotFound) | |
{ | |
var newRequest = request.GetAsync(string.Format("api/ReverseNeft/Reprocess?NEFTReference={0}", postProcessPaymentRequest.Settlement.AuthorizationTransactionId)).Result; | |
if (newRequest.StatusCode == HttpStatusCode.OK) | |
{ | |
var status = newRequest.Content.ReadAsStringAsync().Result; | |
//If status is Posted successfully then payment is confirmed as sweep other wise reset to pending | |
switch (status) | |
{ | |
case "Posted successfully": | |
postProcessPaymentRequest.Settlement.PaymentStatus = PaymentStatus.Swept; | |
break; | |
case "Error Posting transactions": | |
postProcessPaymentRequest.Settlement.PaymentStatus = PaymentStatus.Pending; | |
break; | |
} | |
} | |
} | |
else | |
{ | |
var r = response.Content.ReadAsAsync<object>().Result; | |
_logger.Error(r != null ? r.ToString() : string.Format("Ebips Unknown error {0}", response.StatusCode)); | |
} | |
} | |
catch (System.Exception exception) | |
{ | |
_logger.Error(exception.Message, exception); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment