public async Task <IHttpActionResult> NewFakeDepositInvoice(NewDepositInvoiceBM model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Zarinpal.PaymentGatewayImplementationServicePortTypeClient zp = new Zarinpal.PaymentGatewayImplementationServicePortTypeClient(); var invoice = new DepositInvoice { Amount = model.Amount, PaymentGateway = PaymentGateway.Fake, ReceiverCampaignId = model.ReceiverCampaignId, AccountName = model.Email, ExtraInfoJSON = new ExtraInfoJSON { InfoJSON = model.ExtraInfoJSON } }; db.DepositInvoices.Add(invoice); await db.SaveChangesAsync(); return(Ok()); }
public async Task <IHttpActionResult> NewZarinpalDepositInvoice(NewDepositInvoiceBM model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Zarinpal.PaymentGatewayImplementationServicePortTypeClient zp = new Zarinpal.PaymentGatewayImplementationServicePortTypeClient(); var invoice = new DepositInvoice { Amount = model.Amount, PaymentGateway = PaymentGateway.ZarinPal, ReceiverCampaignId = model.ReceiverCampaignId, AccountName = model.Email, ExtraInfoJSON = new ExtraInfoJSON { InfoJSON = model.ExtraInfoJSON } }; db.DepositInvoices.Add(invoice); await db.SaveChangesAsync(); //NOTE: We do not provide Zarinpal with our customers' email or mobile number //NOTE that we used Async version and changed the original source code, we should check whether this works var resp = await zp.PaymentRequestAsync("YOUR-ZARINPAL-MERCHANT-CODE", model.Amount, model.Description, "", "", Url.Link("VerifyZarinpal", new { id = invoice.Id }) ); var status = resp.Body.Status; var Authority = resp.Body.Authority; if (status == 100) { return(Created("DefaultApi", new { Authority = Authority })); } else { return(InternalServerError(new Exception("Zarinpal gateway error, status:" + status.ToString()))); } }