public static string CreateActiveJson(ChargeResultModel model) { var updateModel = model; updateModel.recurring_application_charge.ConfirmationUrl = null; return(JsonConvert.SerializeObject(updateModel, Formatting.Indented)); }
//Step 2 public ActionResult Auth(string shop, string code, string state) { //security check 1 //compare state value with db value save on install call //if value is not the same stop and exit //security check 2 //valid hostname - ends with myshopify.com and does not contain characters other than letters (a-z), numbers (0-9), dots, and hyphens. if (!App.AllowHostName(shop)) { //exit - send this request home return(RedirectToAction("Index", "Home")); } //security check 3 if (!App.VerifyHmac(Request.QueryString)) { //exit return(RedirectToAction("Index", "Home")); } //make a call to Shopify and get back shop token client = new ShopifyClient(shop); string token = client.GetToken(App.GetAccessTokenUrl(), code); //save token to db System.IO.File.WriteAllText("C:\\MyAppSettings\\token.txt", token);//for demo ONLY //allow customer to view our app //return RedirectToAction("Index", "AppPortal"); //if you are charging for the app uncomment continue below string chargeJson = App.CreateChargeJson(shop); //Call Shopify with json - charge and check if it was created OK var Charge = client.CreateCharge(chargeJson, token); if (Charge.StatusCode == System.Net.HttpStatusCode.Created) { //DeserializeObject and save to db ChargeResultModel chargeResult = JsonConvert.DeserializeObject <ChargeResultModel>(Charge.Content); //send customer to approve or declined the charge return(Redirect(chargeResult.recurring_application_charge.ConfirmationUrl)); } else { //something is wrong //check errors return(RedirectToAction("ErrorPage", "Home")); } }
public PayAtFawryManager(IConfiguration configuration) : base(configuration) { _configuration = configuration; ChargeResultModel = new ChargeResultModel(); }