public ZarinpalResult <ZarinpalVerificationResponseModel> InvokePaymentVerification(ZarinpalPaymentVerificationModel model) { var errors = new List <ZarinpalError>(); model = new ZarinpalPaymentVerificationModel(_configuration.Token, model.Amount, model.Authority); model.ValidateModel(errors); if (errors.Any()) { return(ZarinpalResult <ZarinpalVerificationResponseModel> .Failed(errors.ToArray())); } var response = StartPayment(model, ZarinpalRequestMethod.Post, _verifyUrl); if (string.IsNullOrWhiteSpace(response.Result)) { return(ZarinpalResult <ZarinpalVerificationResponseModel> .Failed(new ZarinpalError { Code = "-6000", Description = "Could not fetch response." })); } if (!response.Succeeded) { return(ZarinpalResult <ZarinpalVerificationResponseModel> .Failed(new ZarinpalError { Code = "-7000", Description = "could not read response." })); } var verificationResult = JsonConvert.DeserializeObject <ZarinpalVerificationResponseModel>(response.Result); return(ZarinpalResult <ZarinpalVerificationResponseModel> .Invoke(verificationResult)); }
public async Task <ZarinpalResult <ZarinpalVerificationResponseModel> > InvokePaymentVerificationAsync(ZarinpalPaymentVerificationModel model) { var errors = new List <ZarinpalError>(); model = new ZarinpalPaymentVerificationModel(_configuration.Token, model.Amount, model.Authority); model.ValidateModel(errors); if (errors.Any()) { return(ZarinpalResult <ZarinpalVerificationResponseModel> .Failed(errors.ToArray())); } var response = await StartPaymentAsync(model, ZarinpalRequestMethod.Post, _verifyUrl); if (string.IsNullOrWhiteSpace(response.Result)) { return(ZarinpalResult <ZarinpalVerificationResponseModel> .Failed()); } if (!response.Succeeded) { return(ZarinpalResult <ZarinpalVerificationResponseModel> .Failed()); } var verificationResult = JsonConvert.DeserializeObject <ZarinpalVerificationResponseModel>(response.Result); return(ZarinpalResult <ZarinpalVerificationResponseModel> .Invoke(verificationResult)); }
public async Task <ZarinpalResult <ZarinpalVerificationResponseModel> > VerifyAsync(ZarinpalPaymentVerificationModel model) { var errors = new List <ZarinpalError>(); model = new ZarinpalPaymentVerificationModel(_configuration.Token, model.Amount, model.Authority); model.ValidateModel(errors); if (errors.Any()) { return(ZarinpalResult <ZarinpalVerificationResponseModel> .Failed(errors.ToArray())); } var t = await PostRequestBase <ZarinpalVerificationResponseModel, ZarinpalPaymentVerificationModel>( model, _verifyUrl); return(!t.Succeeded ? ZarinpalResult <ZarinpalVerificationResponseModel> .Failed(errors.ToArray()) : ZarinpalResult <ZarinpalVerificationResponseModel> .Invoke(t.Result)); }