public override ProcessPaymentResult ProcessPayment(ProcessPaymentEvaluationContext context) { var retVal = new ProcessPaymentResult(); var request = PrepareProcessPaymentRequest(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"]; if (IsSeparatePaymentAction()) { retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Authorized; context.Payment.AuthorizedDate = DateTime.UtcNow; } else { retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid; context.Payment.AuthorizedDate = context.Payment.CapturedDate = DateTime.UtcNow; context.Payment.IsApproved = true; } retVal.IsSuccess = true; retVal.RedirectUrl = string.Format("{0}/{1}?id={2}", context.Store.Url, ThankYouPageRelativeUrl, context.Order.Id); } 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); }
// [Trait("Category", "CI")] public void ProcessPayment_failing() { //arrange var request = PrepareProcessPaymentRequest(false); //act var reply = NVPClient.RunTransaction(request); //assert Assert.Equal("ACCEPT", reply["decision"]); Assert.Equal("100", reply["reasonCode"]); }
public override VoidProcessPaymentResult VoidProcessPayment(VoidProcessPaymentEvaluationContext context) { var retVal = new VoidProcessPaymentResult(); Hashtable request = new Hashtable(); request.Add("ccAuthReversalService_run", "true"); request.Add("ccAuthReversalService_authRequestID", context.Payment.OuterId); request.Add("merchantID", MerchantId); request.Add("merchantReferenceCode", context.Payment.Number); request.Add("purchaseTotals_currency", context.Payment.Currency.ToString()); request.Add("item_0_unitPrice", context.Payment.Sum.ToString()); //request.Add("item_0_quantity", "1"); 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) { retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Voided; context.Payment.VoidedDate = context.Payment.CancelledDate = DateTime.UtcNow; retVal.IsSuccess = true; } else { 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); }
static void Main(string[] args) { Hashtable request = new Hashtable(); // we will let the client pick up the merchantID // from the config file. In multi-merchant scenarios, // you would set a merchantID in each request. // this sample requests both auth and capture // Credit Card Authorization request.Add("ccAuthService_run", "true"); // Credit Card Capture request.Add("ccCaptureService_run", "true"); // add required fields request.Add("merchantReferenceCode", "your_merchant_reference_code"); request.Add("billTo_firstName", "John"); request.Add("billTo_lastName", "Doe"); request.Add("billTo_street1", "1295 Charleston Road"); request.Add("billTo_city", "Mountain View"); request.Add("billTo_postalCode", "94043"); request.Add("billTo_state", "CA"); request.Add("billTo_country", "US"); request.Add("billTo_email", "*****@*****.**"); request.Add("billTo_ipAddress", "10.7.111.111"); request.Add("card_accountNumber", "4111111111111111"); request.Add("card_expirationMonth", "12"); request.Add("card_expirationYear", "2020"); request.Add("purchaseTotals_currency", "USD"); // there are two items in this sample request.Add("item_0_unitPrice", "12.34"); request.Add("item_1_unitPrice", "56.78"); // add optional fields here per your business needs try { Hashtable reply = NVPClient.RunTransaction(request); SaveOrderState(); ProcessReply(reply); } /*** There are many specific exceptions that could be caught here. Only a few are provided as examples. * This is a Windows Communication Foundation (WCF) Client and uses exceptions from the System.ServiceModel * Namespaces. The System.Security.Cryptography and System.Net Namespaces also contain relevant exceptions. * Please refer to the Microsoft documentation to better understand what these exceptions mean. * ***/ //System.ServiceModel Exception examples. catch (EndpointNotFoundException e) { // This is thrown when a remote endpoint could not be found or reached. // The remote endpoint is down, the client network connection is down, // the remote endpoint is unreachable, or because the remote network is unreachable. SaveOrderState(); HandleException(e); } catch (ChannelTerminatedException e) { // This is typically thrown on the client when a channel is terminated due to the server closing the connection. SaveOrderState(); HandleException(e); } //System.ServiceModel.Security Exception example. catch (MessageSecurityException e) { //Represents an exception that occurred when there is something wrong with the security applied on a message. Possibly a bad signature. SaveOrderState(); HandleSecurityException(e); } //System.Security.Cryptography exception catch (CryptographicException ce) { //Represents a problem with your X509 certificate (.p12 file) or a problem creating a signature from the certificate. SaveOrderState(); HandleCryptoException(ce); } //System.Net exception catch (WebException we) { //The WebException class is thrown by classes descended from WebRequest and WebResponse that implement pluggable protocols for accessing the Internet. SaveOrderState(); HandleWebException(we); } //Any other exception! catch (Exception e) { SaveOrderState(); HandleException(e); } Console.WriteLine("Press Return to end..."); Console.ReadLine(); }
public static void ThreadMethod() { Interlocked.Increment(ref threadCount); Hashtable request = new Hashtable(); // we will let the client pick up the merchantID // from the config file. In multi-merchant scenarios, // you would set a merchantID in each request. // this sample requests both auth and capture // Credit Card Authorization request.Add("ccAuthService_run", "true"); // Credit Card Capture request.Add("ccCaptureService_run", "true"); // add required fields request.Add("merchantReferenceCode", "your_merchant_reference_code"); request.Add("billTo_firstName", "John"); request.Add("billTo_lastName", "Doe"); request.Add("billTo_street1", "1295 Charleston Road"); request.Add("billTo_city", "Mountain View"); request.Add("billTo_postalCode", "94043"); request.Add("billTo_state", "CA"); request.Add("billTo_country", "US"); request.Add("billTo_email", "*****@*****.**"); request.Add("billTo_ipAddress", "10.7.111.111"); request.Add("card_accountNumber", "4111111111111111"); request.Add("card_expirationMonth", "12"); request.Add("card_expirationYear", "2020"); request.Add("purchaseTotals_currency", "USD"); // there are two items in this sample request.Add("item_0_unitPrice", "12.34"); request.Add("item_1_unitPrice", "56.78"); // add optional fields here per your business needs try { WriteStatus("Before RunTransaction"); Hashtable reply = NVPClient.RunTransaction(request); WriteStatus("After RunTransaction"); SaveOrderState(); ProcessReply(reply); } catch (WebException we) { SaveOrderState(); HandleWebException(we); } catch (Exception e) { SaveOrderState(); } finally { Interlocked.Decrement(ref threadCount); } }