Exemplo n.º 1
0
        public static CreditCardPaymentResult DoCapture(string authTransactionID)
        {
            CreditCardPaymentResult result = new CreditCardPaymentResult();

            result.TransactionDate = DateTime.UtcNow;
            result.TransactionType = "D";
            result.PayflowRequestID = PayPal.Payments.Common.Utility.PayflowUtility.RequestId;

            // Create PayflowConnectionData object
            PayPal.Payments.DataObjects.PayflowConnectionData pfCnn = new PayPal.Payments.DataObjects.PayflowConnectionData(_payflowHost, _payflowPort, _payflowTimeout, _proxyHost, _proxyPort, _proxyLogon, _proxyPassword);

            // Prepare user credentials
            PayPal.Payments.DataObjects.UserInfo user = new PayPal.Payments.DataObjects.UserInfo(_payflowUser, _payflowMerchant, _payflowPartner, _payflowPassword);

            // Prepare delayed capture transaction
            PayPal.Payments.Transactions.CaptureTransaction captureTran = new PayPal.Payments.Transactions.CaptureTransaction(authTransactionID, user, pfCnn, result.PayflowRequestID);

            // Submit the transaction and receive the response from Payflow server
            PayPal.Payments.DataObjects.Response response = captureTran.SubmitTransaction();

            // Assign response values to the result object
            if (response != null && response.TransactionResponse != null)
            {
                result.TransactionID = ReplaceNullWithEmptyString(response.TransactionResponse.Pnref);

                result.OriginalTransactionID = ReplaceNullWithEmptyString(response.TransactionResponse.OrigPnref);
                if (result.OriginalTransactionID == "")
                    result.OriginalTransactionID = authTransactionID;

                result.ResultCode = response.TransactionResponse.Result;
                result.ResponseMessage = ReplaceNullWithEmptyString(response.TransactionResponse.RespMsg);

                result.AuthorizationCode = ReplaceNullWithEmptyString(response.TransactionResponse.AuthCode);
                result.AvsMatch = ReplaceNullWithEmptyString(response.TransactionResponse.AVSAddr) + ReplaceNullWithEmptyString(response.TransactionResponse.AVSZip);
                result.CscMatch = ReplaceNullWithEmptyString(response.TransactionResponse.CVV2Match);
                result.InternationalAvs = ReplaceNullWithEmptyString(response.TransactionResponse.IAVS);
            }

            return result;
        }
Exemplo n.º 2
0
        public static CreditCardPaymentResult DoSaleByReference(CreditCardPaymentMethod cc, decimal amount, string description, string comment1, string comment2, string ip, string userAgent)
        {
            CreditCardPaymentResult result = new CreditCardPaymentResult();

            result.TransactionDate = DateTime.UtcNow;
            result.TransactionType = "S";
            result.Amount = amount;
            result.PayflowRequestID = PayPal.Payments.Common.Utility.PayflowUtility.RequestId;
            result.IP = ip;

            // Create PayflowConnectionData object
            PayPal.Payments.DataObjects.PayflowConnectionData pfCnn = new PayPal.Payments.DataObjects.PayflowConnectionData(_payflowHost, _payflowPort, _payflowTimeout, _proxyHost, _proxyPort, _proxyLogon, _proxyPassword);

            // Prepare user credentials
            PayPal.Payments.DataObjects.UserInfo user = new PayPal.Payments.DataObjects.UserInfo(_payflowUser, _payflowMerchant, _payflowPartner, _payflowPassword);

            // Prepare invoice
            PayPal.Payments.DataObjects.Invoice invoice = new PayPal.Payments.DataObjects.Invoice();

            invoice.Amt = new PayPal.Payments.DataObjects.Currency((decimal)amount);
            invoice.Comment1 = comment1;
            invoice.Comment2 = comment2;
            invoice.Desc = description;

            invoice.CustomerInfo = new PayPal.Payments.DataObjects.CustomerInfo();
            invoice.CustomerInfo.CustId = cc.ExternalType + "-" + cc.ExternalID;
            invoice.CustomerInfo.CustIP = cc.IP;
            invoice.CustomerInfo.CustCode = cc.ExternalType + "-" + cc.ExternalID;

            invoice.BrowserInfo = new PayPal.Payments.DataObjects.BrowserInfo();
            invoice.BrowserInfo.BrowserUserAgent = userAgent;

            invoice.BillTo = new PayPal.Payments.DataObjects.BillTo();
            invoice.BillTo.FirstName = cc.FirstName;
            invoice.BillTo.LastName = cc.LastName;
            invoice.BillTo.Street = cc.Address1;
            invoice.BillTo.BillToStreet2 = cc.Address2;
            invoice.BillTo.City = cc.City;
            invoice.BillTo.State = cc.State;
            invoice.BillTo.Zip = cc.Zip;
            invoice.BillTo.BillToCountry = cc.CountryID.ToString();
            invoice.BillTo.Email = cc.Email;
            invoice.BillTo.BillToPhone2 = cc.MobilePhone;

            invoice.ShipTo = invoice.BillTo.Copy();

            // Prepare credit card information
            PayPal.Payments.DataObjects.CreditCard creditCard = new PayPal.Payments.DataObjects.CreditCard("", cc.CcExpDate.ToString("MMyy"));
            creditCard.Name = (invoice.BillTo.FirstName + " " + invoice.BillTo.LastName).Trim();

            PayPal.Payments.DataObjects.CardTender cardTender = new PayPal.Payments.DataObjects.CardTender(creditCard);

            // Prepare reference transaction
            PayPal.Payments.Transactions.ReferenceTransaction refTran = new PayPal.Payments.Transactions.ReferenceTransaction("S", cc.LastApprovedTransactionID, user, pfCnn, invoice, cardTender, result.PayflowRequestID);

            // Submit the transaction and receive the response from Payflow server
            PayPal.Payments.DataObjects.Response response = refTran.SubmitTransaction();

            // Assign response values to the result object
            if (response != null && response.TransactionResponse != null)
            {
                result.TransactionID = ReplaceNullWithEmptyString(response.TransactionResponse.Pnref);
                result.OriginalTransactionID = ReplaceNullWithEmptyString(response.TransactionResponse.OrigPnref);
                result.ResultCode = response.TransactionResponse.Result;
                result.ResponseMessage = ReplaceNullWithEmptyString(response.TransactionResponse.RespMsg);

                result.AuthorizationCode = ReplaceNullWithEmptyString(response.TransactionResponse.AuthCode);
                result.AvsMatch = ReplaceNullWithEmptyString(response.TransactionResponse.AVSAddr) + ReplaceNullWithEmptyString(response.TransactionResponse.AVSZip);
                result.CscMatch = ReplaceNullWithEmptyString(response.TransactionResponse.CVV2Match);
                result.InternationalAvs = ReplaceNullWithEmptyString(response.TransactionResponse.IAVS);
            }

            return result;
        }
Exemplo n.º 3
0
        public static CreditCardPaymentResult DoVoid(string originalTransactionID, string externalType, int externalID, string description, string comment1, string comment2, string ip, string userAgent)
        {
            CreditCardPaymentResult result = new CreditCardPaymentResult();

            result.TransactionDate = DateTime.UtcNow;
            result.TransactionType = "V";
            result.PayflowRequestID = PayPal.Payments.Common.Utility.PayflowUtility.RequestId;
            result.IP = ip;

            // Create PayflowConnectionData object
            PayPal.Payments.DataObjects.PayflowConnectionData pfCnn = new PayPal.Payments.DataObjects.PayflowConnectionData(_payflowHost, _payflowPort, _payflowTimeout, _proxyHost, _proxyPort, _proxyLogon, _proxyPassword);

            // Prepare user credentials
            PayPal.Payments.DataObjects.UserInfo user = new PayPal.Payments.DataObjects.UserInfo(_payflowUser, _payflowMerchant, _payflowPartner, _payflowPassword);

            // Prepare invoice
            PayPal.Payments.DataObjects.Invoice invoice = new PayPal.Payments.DataObjects.Invoice();

            invoice.Comment1 = comment1;
            invoice.Comment2 = comment2;
            invoice.Desc = description;

            invoice.CustomerInfo = new PayPal.Payments.DataObjects.CustomerInfo();
            invoice.CustomerInfo.CustId = externalType + "-" + externalID;
            invoice.CustomerInfo.CustIP = ip;
            invoice.CustomerInfo.CustCode = externalType + "-" + externalID;

            invoice.BrowserInfo = new PayPal.Payments.DataObjects.BrowserInfo();
            invoice.BrowserInfo.BrowserUserAgent = userAgent;

            invoice.BillTo = new PayPal.Payments.DataObjects.BillTo();

            // Prepare void transaction
            PayPal.Payments.Transactions.VoidTransaction voidTran = new PayPal.Payments.Transactions.VoidTransaction(originalTransactionID, user, pfCnn, invoice, result.PayflowRequestID);

            // Submit the transaction and receive the response from Payflow server
            PayPal.Payments.DataObjects.Response response = voidTran.SubmitTransaction();

            // Assign response values to the result object
            if (response != null && response.TransactionResponse != null)
            {
                result.TransactionID = ReplaceNullWithEmptyString(response.TransactionResponse.Pnref);

                result.OriginalTransactionID = ReplaceNullWithEmptyString(response.TransactionResponse.OrigPnref);
                if (result.OriginalTransactionID == "")
                    result.OriginalTransactionID = originalTransactionID;

                result.ResultCode = response.TransactionResponse.Result;
                result.ResponseMessage = ReplaceNullWithEmptyString(response.TransactionResponse.RespMsg);

                result.AuthorizationCode = ReplaceNullWithEmptyString(response.TransactionResponse.AuthCode);
                result.AvsMatch = ReplaceNullWithEmptyString(response.TransactionResponse.AVSAddr) + ReplaceNullWithEmptyString(response.TransactionResponse.AVSZip);
                result.CscMatch = ReplaceNullWithEmptyString(response.TransactionResponse.CVV2Match);
                result.InternationalAvs = ReplaceNullWithEmptyString(response.TransactionResponse.IAVS);
            }

            return result;
        }