public override void HandleIPN(PaypalContext paypalContext) { if (paypalContext.PaymentInformation.PaymentStatusType == PaymentStatusType.Refunded) { var customer = new PlanCustomer { Email = paypalContext.BuyerInformation.PayerEmail }; int count; if (!int.TryParse(paypalContext.BasicInformation.ItemNumber, out count)) { count = 0; } var product = new PlanProduct { Name = paypalContext.BasicInformation.ItemName, Count = count }; this.PlanService.QuitProPlan(customer, product); this.MailService.SendOpsNotification("Refund from Pro!", $"Welcome to join us - from FewBox {paypalContext.BasicInformation.ItemName} team.", new List <string> { paypalContext.BuyerInformation.PayerEmail }); this.Logger.LogDebug($"Refund from {customer.Email}"); } else { this.Approver.HandleIPN(paypalContext); } }
public async Task <StatusCodeResult> ReceiveAsync() { var paymentInfo = new PaymentInfo(); using (StreamReader reader = new StreamReader(this.Request.Body, Encoding.ASCII)) { paymentInfo.Body = await reader.ReadToEndAsync(); } using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded")); string content = $"cmd=_notify-validate&{paymentInfo.Body}"; var httpContent = new StringContent(content); HttpResponseMessage response = await httpClient.PostAsync(this.PaypalConfig.Url, httpContent); response.EnsureSuccessStatusCode(); string responseString = await response.Content.ReadAsStringAsync(); this.Logger.LogTrace(@"{0}: {1}", paymentInfo.Body, responseString); this.MailService.SendOpsNotification(responseString, paymentInfo.Body, new List <string> { this.FewBoxSDKConfig.OpsEmail }); if (responseString.Equals("VERIFIED")) { // check that Payment_status=Completed // check that Txn_id has not been previously processed // check that Receiver_email is your Primary PayPal email // check that Payment_amount/Payment_currency are correct // process payment NameValueCollection qureyParams = System.Web.HttpUtility.ParseQueryString(WebUtility.UrlDecode(paymentInfo.Body)); PaypalContext paypalContext = new PaypalContext(qureyParams); if (paypalContext.PaymentInformation.PaymentStatusType == PaymentStatusType.Completed && paypalContext.BasicInformation.ReceiverEmail == this.PaypalConfig.ReceiverEmail && paypalContext.CurrencyAndCurrrencyExchange.MCCurrency == this.PaypalConfig.Currency) { this.PaypalService.HandleIPN(paypalContext); } else { return(Unauthorized()); } } else if (responseString.Equals("INVALID")) { this.Logger.LogError(paymentInfo.Body); return(Unauthorized()); } else { this.Logger.LogError(responseString); return(BadRequest()); } } return(Ok()); }
public override void HandleIPN(PaypalContext paypalContext) { this.Logger.LogError("Handle IPN error!"); }
public abstract void HandleIPN(PaypalContext paypalContext);