/// <summary> /// Cancels the given invoice. No Verifying request will be sent to the gateway. /// </summary> /// <param name="onlinePayment"></param> /// <param name="invoice"></param> /// <param name="cancellationReason">The reason for canceling the operation. It will be saved in Message field in database.</param> /// <exception cref="InvoiceNotFoundException"></exception> public static IPaymentCancelResult Cancel( this IOnlinePayment onlinePayment, IPaymentFetchResult invoice, string cancellationReason = null) { if (invoice == null) { throw new ArgumentNullException(nameof(invoice)); } return(onlinePayment.CancelAsync(invoice.TrackingNumber, cancellationReason).GetAwaiter().GetResult()); }
/// <summary> /// Cancels the given invoice. No Verifying request will be sent to the gateway. /// </summary> /// <param name="onlinePayment"></param> /// <param name="invoice"></param> /// <param name="cancellationReason">The reason for canceling the operation. It will be saved in Message field in database.</param> /// <param name="cancellationToken"></param> /// <exception cref="InvoiceNotFoundException"></exception> public static Task <IPaymentCancelResult> CancelAsync( this IOnlinePayment onlinePayment, IPaymentFetchResult invoice, string cancellationReason = null, CancellationToken cancellationToken = default) { if (invoice == null) { throw new ArgumentNullException(nameof(invoice)); } return(onlinePayment.CancelAsync(invoice.TrackingNumber, cancellationReason, cancellationToken)); }
// It's better to set no HttpMethods(HttpGet, HttpPost, etc.) for the Verify action, // because the banks send their information with different http methods // درگاههای بانکی، اطلاعات خود را با متدهای مختلفی ارسال میکنند // بنابراین بهتر است هیچگونه خصوصیتی برای این اکشن متد در نظر گرفته نشود public async Task <ActionResult> Verify() { var invoice = await _onlinePayment.FetchAsync(); if (Is_There_Still_Product_In_Shop(invoice.TrackingNumber)) { var verifyResult = await _onlinePayment.VerifyAsync(invoice); return(View(verifyResult)); } var cancelResult = await _onlinePayment.CancelAsync(invoice, cancellationReason : "Sorry, We have no more products to sell."); return(View("CancelResult", cancelResult)); }
// It's better to set no HttpMethods(HttpGet, HttpPost, etc.) for the Verify action, // because the banks send their information with different HTTP methods public async Task <ActionResult> Verify() { var invoice = await _onlinePayment.FetchAsync(); // Check if the invoice is new or it's already processed before. if (invoice.Status == PaymentFetchResultStatus.AlreadyProcessed) { // You can also see if the invoice is already verified before. var isAlreadyVerified = invoice.IsAlreadyVerified; return(Content("The payment is already processed before.")); } // This is an example of cancelling an invoice when you think that the payment process must be stopped. if (!Is_There_Still_Product_In_Shop(invoice.TrackingNumber)) { var cancelResult = await _onlinePayment.CancelAsync(invoice, cancellationReason : "Sorry, We have no more products to sell."); return(View("CancelResult", cancelResult)); } var verifyResult = await _onlinePayment.VerifyAsync(invoice); return(View(verifyResult)); }
/// <summary> /// Cancels the given invoice. No Verifying request will be sent to the gateway. /// </summary> /// <param name="onlinePayment"></param> /// <param name="trackingNumber">The tracking number of the invoice which must be verified.</param> /// <param name="cancellationReason">The reason for canceling the operation. It will be saved in Message field in database.</param> /// <exception cref="InvoiceNotFoundException"></exception> public static IPaymentCancelResult Cancel( this IOnlinePayment onlinePayment, long trackingNumber, string cancellationReason = null) => onlinePayment.CancelAsync(trackingNumber, cancellationReason).GetAwaiter().GetResult();