public override CaptureProcessPaymentResult CaptureProcessPayment(CaptureProcessPaymentEvaluationContext context) { var retVal = new CaptureProcessPaymentResult(); var request = PrepareCaptureProcessPaymentRequest(context); var reply = NVPClient.RunTransaction(request); if (reply != null && reply.ContainsKey("decision") && reply.ContainsKey("reasonCode")) { var decision = (string)reply["decision"]; var reasonCode = int.Parse((string)reply["reasonCode"]); var isAccept = decision.Equals("ACCEPT", StringComparison.InvariantCultureIgnoreCase); var isSuccessReasonCode = reasonCode == 100; if (isAccept && isSuccessReasonCode) { context.Payment.OuterId = (string)reply["requestID"]; retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid; context.Payment.CapturedDate = DateTime.UtcNow; context.Payment.IsApproved = true; retVal.IsSuccess = true; } else { if (reasonCode == 101) throw new NullReferenceException(string.Format("result from cyber source, not success, decision is {0}, reasonCode is {1}, full info of reason is {2}", decision, reasonCode, EnumerateValues(reply, "missingField"))); if (reasonCode == 102) throw new NullReferenceException(string.Format("result from cyber source, not success, decision is {0}, reasonCode is {1}, full info of reason is {2}", decision, reasonCode, EnumerateValues(reply, "invalidField"))); if (reasonCode == 204) throw new NullReferenceException(string.Format("result from cyber source, not success, decision is {0}, reasonCode is {1}, full info of reason is not enough funds", decision, reasonCode)); throw new NullReferenceException(string.Format("result from cyber source, not success, decision is {0}, reasonCode is {1}", decision, reasonCode)); } } else { throw new NullReferenceException("no reply from cyber source"); } return retVal; }
public override CaptureProcessPaymentResult CaptureProcessPayment(CaptureProcessPaymentEvaluationContext context) { var retVal = new CaptureProcessPaymentResult(); var webClient = new WebClient(); var form = new NameValueCollection(); form.Add("x_login", ApiLogin); form.Add("x_tran_key", TxnKey); form.Add("x_delim_data", "TRUE"); form.Add("x_delim_char", "|"); form.Add("x_encap_char", ""); form.Add("x_version", GetApiVersion()); form.Add("x_method", "CC"); form.Add("x_currency_code", context.Payment.Currency.ToString()); form.Add("x_type", "CAPTURE_ONLY"); var orderTotal = Math.Round(context.Payment.Sum, 2); form.Add("x_amount", orderTotal.ToString("0.00", CultureInfo.InvariantCulture)); //x_trans_id. When x_test_request (sandbox) is set to a positive response, //or when Test mode is enabled on the payment gateway, this value will be "0". form.Add("x_trans_id", context.Payment.OuterId); var responseData = webClient.UploadValues(GetAuthorizeNetUrl(), form); var reply = Encoding.ASCII.GetString(responseData); if (!string.IsNullOrEmpty(reply)) { string[] responseFields = reply.Split('|'); switch (responseFields[0]) { case "1": retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid; retVal.OuterId = context.Payment.OuterId = string.Format("{0},{1}", responseFields[6], responseFields[4]); retVal.IsSuccess = true; context.Payment.IsApproved = true; break; case "2": throw new NullReferenceException(string.Format("Declined ({0}: {1})", responseFields[2], responseFields[3])); case "3": throw new NullReferenceException(string.Format("Error: {0}", reply)); } } else { throw new NullReferenceException("Authorize.NET unknown error"); } return retVal; }
public override CaptureProcessPaymentResult CaptureProcessPayment(CaptureProcessPaymentEvaluationContext context) { if (context == null || context.Payment == null) throw new ArgumentNullException("paymentEvaluationContext"); CaptureProcessPaymentResult retVal = new CaptureProcessPaymentResult(); if (!context.Payment.IsApproved && (context.Payment.PaymentStatus == PaymentStatus.Authorized || context.Payment.PaymentStatus == PaymentStatus.Cancelled)) { try { var config = GetConfigMap(); var service = new PayPalAPIInterfaceServiceService(config); DoCaptureReq doCaptureRequest = GetDoCaptureRequest(context.Payment); var doCaptureResponse = service.DoCapture(doCaptureRequest); CheckResponse(doCaptureResponse); if(doCaptureResponse.DoCaptureResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.COMPLETED) { retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid; context.Payment.CapturedDate = DateTime.UtcNow; context.Payment.IsApproved = true; retVal.IsSuccess = true; } } catch(Exception ex) { retVal.ErrorMessage = ex.Message; } } return retVal; }
public override CaptureProcessPaymentResult CaptureProcessPayment(CaptureProcessPaymentEvaluationContext context) { if (context == null) throw new ArgumentNullException("context"); if (context.Payment == null) throw new ArgumentNullException("context.Payment"); var retVal = new CaptureProcessPaymentResult(); Uri resourceUri = new Uri(string.Format("{0}/{1}", _euroTestBaseUrl, context.Payment.OuterId)); var connector = Connector.Create(AppSecret); Order order = new Order(connector, resourceUri) { ContentType = _contentType }; order.Fetch(); var reservation = order.GetValue("reservation") as string; if (!string.IsNullOrEmpty(reservation)) { try { Configuration configuration = new Configuration(Country.Code.SE, Language.Code.SV, Currency.Code.SEK, Encoding.Sweden) { Eid = Convert.ToInt32(AppKey), Secret = AppSecret, IsLiveMode = false }; Api.Api api = new Api.Api(configuration); var response = api.Activate(reservation); retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid; context.Payment.CapturedDate = DateTime.UtcNow; context.Payment.IsApproved = true; retVal.IsSuccess = true; retVal.OuterId = context.Payment.OuterId = response.InvoiceNumber; } catch(Exception ex) { retVal.ErrorMessage = ex.Message; } } else { retVal.ErrorMessage = "No reservation for this order"; } return retVal; }