public ActionResult PaymentResult(string status, string token) { try { if (string.IsNullOrWhiteSpace(status)) { ModelState.AddModelError("ServerError", "پاسخی از سمت درگاه دریافت نشد"); return(View()); } if (status != "success") { ModelState.AddModelError("ServerError", status); return(View()); } if (string.IsNullOrWhiteSpace(token)) { ModelState.AddModelError("ServerError", "توکن از سمت سرور ارسال نشد"); return(View()); } int amount; string invoiceReference = GetReference(token, out amount); if (string.IsNullOrWhiteSpace(invoiceReference)) { ModelState.AddModelError("ServerError", "شماره فاکتور یافت نشد"); return(View()); } var verifyRequest = new WalletaVerifyRequestModel(MerchantCode, token, invoiceReference, amount); var verifyResult = WalletaPaymentService.VerifyPayment(verifyRequest); if (verifyResult == null) { ModelState.AddModelError("ServerError", "پاسخ تایید تراکنش از سمت درگاه دریافت نشد"); return(View()); } ViewData["VerifyJsonResponse"] = new JavaScriptSerializer().Serialize(verifyResult); return(View(verifyResult)); } finally { RemoveReferece(token); } }
public ActionResult Index(SimplePayModel model) { if (!ModelState.IsValid) { return(View(model)); } string invoiceReference = DateTime.Now.Ticks.ToString(); var tokenRequest = new WalletaTokenRequestModel ( MerchantCode, invoiceReference, DateTime.Now, model.Amount, "نام", "نام خانوادگی", model.NationalCode, model.Mobile, CallBack ); tokenRequest.items = new Item[] { new Item { reference = "PK-0001", name = "کالای تست ۱", quantity = 2, unit_price = model.Amount / 2, unit_discount = 0, unit_tax_amount = 0, total_amount = model.Amount, }, new Item { name = "هزینه ارسال", quantity = 1, unit_price = 10000, unit_discount = 0, unit_tax_amount = 0, total_amount = 10000, } }; var result = WalletaPaymentService.GetToken(tokenRequest); if (result == null) { ModelState.AddModelError("خطای سرویس", "پاسخی از سمت سرویس دریافت نشد"); return(View(model)); } if (result.invalid_fields != null && result.invalid_fields.Length > 0) { foreach (var field in result.invalid_fields) { ModelState.AddModelError(field.field, field.field + ": " + field.message); } return(View(model)); } if (string.IsNullOrWhiteSpace(result.token)) { ModelState.AddModelError(result.type, result.message); return(View(model)); } SaveReference(result.token, invoiceReference, model.Amount); return(Redirect(CpgUrl.TrimEnd('/') + "/" + result.token)); }