Esempio n. 1
0
        public static bool CreateCustomerProfileTransactionAuthCapture(Site site, Invoice invoice, Customer customer, CreditCard creditCard, out long transactionId, out string message, out bool cancel)
        {
            cancel = false;
            MerchantAuthenticationType merchantAT = new MerchantAuthenticationType();

            merchantAT.name           = site.AuthorizeLoginId;
            merchantAT.transactionKey = site.AuthorizeTransactionKey;

            ProfileTransactionType      profileTT   = new ProfileTransactionType();
            ProfileTransAuthCaptureType profileTACT = new ProfileTransAuthCaptureType();

            OrderExType orderET = new OrderExType();

            orderET.invoiceNumber = invoice.Id.ToString();

            profileTACT.amount                   = invoice.Amount;
            profileTACT.customerProfileId        = customer.AuthorizeProfileId;
            profileTACT.customerPaymentProfileId = creditCard.AuthorizePaymentProfileId;
            profileTACT.order = orderET;

            profileTT.Item = profileTACT;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;// comparable to modern browsers
            ServiceSoapClient client = new ServiceSoapClient();
            CreateCustomerProfileTransactionResponseType resp = client.CreateCustomerProfileTransaction(merchantAT, profileTT, String.Empty);

            if (resp.directResponse != null)
            {
                PaymentGatewayResponse paymentGatewayResponse = new PaymentGatewayResponse(resp.directResponse);
                transactionId = paymentGatewayResponse.TransactionId;
                message       = paymentGatewayResponse.ResponseReasonText;

                if (!string.IsNullOrEmpty(paymentGatewayResponse.ResponseReasonText))
                {
                    cancel = paymentGatewayResponse.ResponseReasonText.ToLower().Contains("the credit card number is invalid") ||
                             paymentGatewayResponse.ResponseReasonText.ToLower().Contains("the credit card expiration date is invalid") ||
                             paymentGatewayResponse.ResponseReasonText.ToLower().Contains("the credit card has expired");
                }
            }
            else
            {
                transactionId = 0;
                if (resp.messages.Length > 0)
                {
                    message = resp.messages[0].text;
                }
                else
                {
                    message = "";
                }
            }

            return(resp.resultCode == MessageTypeEnum.Ok);
        }
Esempio n. 2
0
        public static bool CreateCustomerProfileTransactionAuthCapture(SiteDT site, InvoiceDT invoice, CustomerDT customer, CreditCardDT creditCard, out long transactionId, out string message, out string code)
        {
            MerchantAuthenticationType merchantAT = new MerchantAuthenticationType();

            merchantAT.name           = site.AuthorizeLoginId;
            merchantAT.transactionKey = site.AuthorizeTransactionKey;

            ProfileTransactionType      profileTT   = new ProfileTransactionType();
            ProfileTransAuthCaptureType profileTACT = new ProfileTransAuthCaptureType();

            OrderExType orderET = new OrderExType();

            orderET.invoiceNumber = invoice.Id.ToString();

            profileTACT.amount                   = invoice.Amount;
            profileTACT.customerProfileId        = customer.AuthorizeProfileId;
            profileTACT.customerPaymentProfileId = creditCard.AuthorizePaymentProfileId;
            profileTACT.order = orderET;

            profileTT.Item = profileTACT;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            ServiceSoapClient client = new ServiceSoapClient();
            CreateCustomerProfileTransactionResponseType resp = client.CreateCustomerProfileTransaction(merchantAT, profileTT, String.Empty);

            code = string.Empty;

            if (resp.directResponse != null)
            {
                PaymentGatewayResponse paymentGatewayResponse = new PaymentGatewayResponse(resp.directResponse);
                transactionId = paymentGatewayResponse.TransactionId;
                message       = paymentGatewayResponse.ResponseReasonText;

                code = resp.messages != null && resp.messages.Count() > 0 ? resp.messages.Select(x => x.code + " - " + x.text).Aggregate((a, b) => a + "; " + b) : string.Empty;
            }
            else
            {
                transactionId = 0;
                if (resp.messages.Length > 0)
                {
                    message = resp.messages[0].text;
                }
                else
                {
                    message = "";
                }
            }

            return(resp.resultCode == MessageTypeEnum.Ok);
        }