public ActionResult Callback(string id) { var checkSum = Request.Headers["QuickPay-Checksum-SHA256"]; // Get the Payload data var req = Request.InputStream; req.Seek(0, SeekOrigin.Begin); var json = new StreamReader(req).ReadToEnd(); LogHelper.Info<CallbackController>(() => "[BODY] : " + json); var gateway = MerchelloContext.Current.Gateways.Payment.GetProviderByKey(Guid.Parse(Constants.ProviderId)); var gatewaySettings = gateway.ExtendedData.GetProviderSettings(); var compute = Sign(json, gatewaySettings.PrivateKey); // Private Key for the Payment Window! Not the API key. if (!checkSum.Equals(compute)) { LogHelper.Warn<CallbackController>("Checksum did not compute : " + checkSum + "\r\n" + json); throw new Exception("MD5 Check does not compute"); } QuickPayResponseModel callbackInput; try { callbackInput = JsonConvert.DeserializeObject<QuickPayResponseModel>(json); } catch (Exception ex) { LogHelper.Error<CallbackController>("Unable to deserialize json from QuickPay callback", ex); return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } if (!callbackInput.Accepted) { LogHelper.Info<CallbackController>("Payment not accepted by QuickPay"); return Content("Payment not accepted by QuickPay"); } if (callbackInput.Order_Id.StartsWith("test_")) { LogHelper.Warn<CallbackController>("QuickPay is in test mode. The payment provider is unable to identify the invoice to apply the payment to, since the order_id was returned as " + callbackInput.Order_Id); return Content("QuickPay Test Mode Detected"); } var invoiceNumber = int.Parse(callbackInput.Order_Id); var invoice = MerchelloContext.Current.Services.InvoiceService.GetByInvoiceNumber(invoiceNumber); var paymentGatewayMethod = MerchelloContext.Current.Gateways.Payment.GetPaymentGatewayMethods().Single(x => x.PaymentMethod.ProviderKey == Guid.Parse(Constants.ProviderId)); var args = new ProcessorArgumentCollection(); args.Add(Constants.ExtendedDataKeys.PaymentCurrency, callbackInput.Currency); args.Add(Constants.ExtendedDataKeys.PaymentAmount, callbackInput.Operations.Where(x => !x.Pending).Sum(x => x.Amount).ToString("F0")); args.Add(Constants.ExtendedDataKeys.QuickpayPaymentId, callbackInput.Id.ToString("F0")); var paymentResult = invoice.AuthorizePayment(paymentGatewayMethod, args); Notification.Trigger("OrderConfirmation", paymentResult, new[] { invoice.BillToEmail }); return Content("Hello QuickPay"); }
/// <summary> /// The set purchase order number. /// </summary> /// <param name="args"> /// The <see cref="ProcessorArgumentCollection"/> /// </param> /// <param name="purchaseOrderNumber"> /// The Purchase Order Number. /// </param> public static void SetPurchaseOrderNumber(this ProcessorArgumentCollection args, string purchaseOrderNumber) { if (args.ContainsKey(PurchaseOrderKey)) { args[PurchaseOrderKey] = purchaseOrderNumber; return; } args.Add(PurchaseOrderKey, purchaseOrderNumber); }
/// <summary> /// Utility method to convert payment arguments submitted at checkout to a <see cref="ProcessorArgumentCollection"/> /// </summary> /// <param name="paymentArgs"> /// The payment args. /// </param> /// <returns> /// The <see cref="ProcessorArgumentCollection"/>. /// </returns> internal static ProcessorArgumentCollection ToProcessorArgumentCollection(this IEnumerable <KeyValuePair <string, string> > paymentArgs) { var processorArgs = new ProcessorArgumentCollection(); foreach (var item in paymentArgs) { processorArgs.Add(item.Key, item.Value); } return(processorArgs); }
private void Build(PaymentRequest request) { _invoice = _merchelloContext.Services.InvoiceService.GetByKey(request.InvoiceKey); if (request.PaymentKey != null) { _payment = _merchelloContext.Services.PaymentService.GetByKey(request.PaymentKey.Value); } _paymentGatewayMethod = _merchelloContext.Gateways.Payment.GetPaymentGatewayMethodByKey(request.PaymentMethodKey); _amount = request.Amount; foreach (var arg in request.ProcessorArgs) { _args.Add(arg.Key, arg.Value); } }
/// <summary> /// Set Stripe customer name /// </summary> /// <param name="args"></param> /// <param name="customerEmail"></param> public static void SetCustomerEmail(this ProcessorArgumentCollection args, string customerEmail) { args.Add(Constants.Stripe.ProcessorArguments.CustomerEmail, customerEmail); }
/// <summary> /// Set Stripe charge ID /// </summary> /// <param name="args"></param> /// <param name="chargeId"></param> public static void SetChargeId(this ProcessorArgumentCollection args, string chargeId) { args.Add(Constants.Stripe.ProcessorArguments.ChargeId, chargeId); }
/// <summary> /// The set payment method token. /// </summary> /// <param name="args"> /// The args. /// </param> /// <param name="paymentMethodToken"> /// The payment method token. /// </param> public static void SetPaymentMethodToken(this ProcessorArgumentCollection args, string paymentMethodToken) { args.Add(Constants.Braintree.ProcessorArguments.PaymentMethodToken, paymentMethodToken); }
public ActionResult Callback(string id) { var checkSum = Request.Headers["QuickPay-Checksum-SHA256"]; // Get the Payload data var req = Request.InputStream; req.Seek(0, SeekOrigin.Begin); var json = new StreamReader(req).ReadToEnd(); LogHelper.Info <CallbackController>(() => "[BODY] : " + json); var gateway = MerchelloContext.Current.Gateways.Payment.GetProviderByKey(Guid.Parse(Constants.ProviderId)); var gatewaySettings = gateway.ExtendedData.GetProviderSettings(); var compute = Sign(json, gatewaySettings.PrivateKey); // Private Key for the Payment Window! Not the API key. if (!checkSum.Equals(compute)) { LogHelper.Warn <CallbackController>("Checksum did not compute : " + checkSum + "\r\n" + json); throw new Exception("MD5 Check does not compute"); } QuickPayResponseModel callbackInput; try { callbackInput = JsonConvert.DeserializeObject <QuickPayResponseModel>(json); } catch (Exception ex) { LogHelper.Error <CallbackController>("Unable to deserialize json from QuickPay callback", ex); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (!callbackInput.Accepted) { LogHelper.Info <CallbackController>("Payment not accepted by QuickPay"); return(Content("Payment not accepted by QuickPay")); } if (callbackInput.Order_Id.StartsWith("test_")) { LogHelper.Warn <CallbackController>("QuickPay is in test mode. The payment provider is unable to identify the invoice to apply the payment to, since the order_id was returned as " + callbackInput.Order_Id); return(Content("QuickPay Test Mode Detected")); } var invoiceNumber = int.Parse(callbackInput.Order_Id); var invoice = MerchelloContext.Current.Services.InvoiceService.GetByInvoiceNumber(invoiceNumber); var paymentGatewayMethod = MerchelloContext.Current.Gateways.Payment.GetPaymentGatewayMethods().Single(x => x.PaymentMethod.ProviderKey == Guid.Parse(Constants.ProviderId)); var args = new ProcessorArgumentCollection(); args.Add(Constants.ExtendedDataKeys.PaymentCurrency, callbackInput.Currency); args.Add(Constants.ExtendedDataKeys.PaymentAmount, callbackInput.Operations.Where(x => !x.Pending).Sum(x => x.Amount).ToString("F0")); args.Add(Constants.ExtendedDataKeys.QuickpayPaymentId, callbackInput.Id.ToString("F0")); var paymentResult = invoice.AuthorizePayment(paymentGatewayMethod, args); Notification.Trigger("OrderConfirmation", paymentResult, new[] { invoice.BillToEmail }); return(Content("Hello QuickPay")); }
/// <summary> /// Sets the payment method nonce. /// </summary> /// <param name="args"> /// The args. /// </param> /// <param name="paymentMethodNonce"> /// The payment method nonce. /// </param> public static void SetPaymentMethodNonce(this ProcessorArgumentCollection args, string paymentMethodNonce) { args.Add(Constants.ProcessorArguments.PaymentMethodNonce, paymentMethodNonce); }
public static void SetPayPalExpressAjaxRequest(this ProcessorArgumentCollection args, bool value) { args.Add("paypalExpressAjax", value.ToString()); }