Exemplo n.º 1
0
        /// <summary>
        /// Create a transactional object for credit or debit cards with the prototype specified.
        /// </summary>
        /// <param name="proto">Contains all the information required to build a transaction.</param>
        /// <param name="card">The card to charge or capture in the process.</param>
        /// <param name="buyer">The buyer for the transaction.</param>
        /// <param name="payer">The payer for the transaction. Can be the same as the buyer.</param>
        /// <param name="transactionType">Whether the transaction should be authorized or charged.</param>
        /// <param name="installments">How many installments to divide the purchase in. Default is 1.</param>
        /// <param name="isDebitTransaction">Whether the transaction should be determined as debit. Default is false.</param>
        /// <param name="dontUseCVV">Whether PayU should be instructed to not use the CVV. Requires previous authorization. Default is false.</param>
        /// <returns>A prepared transactional object to be used with <see cref="ExecuteTransaction"/>.</returns>
        public Transaction BuildCardTransaction(TransactionPrototype proto, Card card, Buyer buyer, Payer payer, TransactionType transactionType,
                                                int installments = 1, bool isDebitTransaction = false, bool dontUseCVV = false)
        {
            var franchise = card.FranchiseCode(isDebitTransaction);

            var baseTx = BuildBaseTransaction(proto, buyer, payer, transactionType);

            if (isDebitTransaction)
            {
                baseTx.DebitCard = card;
                installments     = 1;
            }
            else
            {
                baseTx.CreditCard = card.ToCreditCard(dontUseCVV);
            }

            baseTx.PaymentMethod   = franchise;
            baseTx.ExtraParameters = new RequestExtraParameters
            {
                InstallmentsNumber = installments
            };

            return(baseTx);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a transactional object for PSE debit transactions.
        /// </summary>
        /// <param name="proto">Contains all the information required to build a transaction.</param>
        /// <param name="buyer">The buyer for the transaction.</param>
        /// <param name="payer">The payer for the transaction. Can be the same as the buyer.</param>
        /// <param name="responseURL">The URL to send the user to when the PSE flow ends.</param>
        /// <param name="targetBank">The financial institution redirection to send the user to. <see cref="GetAvailablePSEBanks"/>.</param>
        /// <param name="docType">The Colombian-issued DNI type of the user who will perform the payment..</param>
        /// <param name="document">The Colombian-issued DNI of the user who will perform the payment.</param>
        /// <returns></returns>
        public Transaction BuildPSETransaction(TransactionPrototype proto, Buyer buyer, Payer payer, string responseURL, string targetBank, string docType, string document)
        {
            var baseTx = BuildBaseTransaction(proto, buyer, payer, TransactionType.AuthorizeAndCapture(), true);

            docType = docType.ToUpper();

            var userType = docType == "NIT" ? "J" : "N";

            baseTx.PaymentMethod  = "PSE";
            baseTx.PaymentCountry = "CO";

            baseTx.ExtraParameters = new RequestExtraParameters
            {
                InstallmentsNumber       = null,
                ResponseURL              = responseURL,
                UserIP                   = proto.IPAddress,
                FinancialInstitutionCode = targetBank,
                UserType                 = userType,
                DocumentType             = docType,
                UserDNI                  = document
            };

            return(baseTx);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructs a base transactional structure, universal for payments.
        /// </summary>
        /// <param name="proto">Contains all the information required to build a transaction.</param>
        /// <param name="buyer">The buyer for the transaction.</param>
        /// <param name="payer">The payer for the transaction. Can be the same as the buyer.</param>
        /// <param name="transactionType">Whether the transaction should be authorized or charged.</param>
        /// <returns></returns>
        private Transaction BuildBaseTransaction(TransactionPrototype proto, Buyer buyer, Payer payer,
                                                 TransactionType transactionType, bool useIntValues = false)
        {
            var tax     = 0.0;
            var taxBase = 0.0;

            proto.Country  = proto.Country.ToUpper();
            proto.Currency = proto.Currency.ToUpper();

            if (proto.Country == "CO")
            {
                tax     = proto.Value * 0.19;
                taxBase = proto.Value - tax;
            }



            var valValue   = useIntValues ? Convert.ToInt32(proto.Value).ToString() : proto.Value.ToString(CultureInfo.InvariantCulture);
            var valTax     = useIntValues ? Convert.ToInt32(tax).ToString() : tax.ToString(CultureInfo.InvariantCulture);
            var valTaxBase = useIntValues ? Convert.ToInt32(Convert.ToInt32(valValue) - Convert.ToInt32(valTax)).ToString() : taxBase.ToString(CultureInfo.InvariantCulture);

            var signature = ApiUtil.HashSignature(_apiKey, _merchantID, proto.ReferenceCode, valValue, proto.Currency);

            var additionalValues = new AdditionalValues
            {
                Value   = AdditionalValues.TransactionValue(valValue, proto.Currency),
                Tax     = AdditionalValues.TaxValue(valTax, proto.Currency),
                TaxBase = AdditionalValues.TaxReturnBase(valTaxBase, proto.Currency)
            };

            var order = new Order
            {
                Buyer            = buyer,
                Description      = proto.Description,
                Language         = _language,
                Signature        = signature,
                AccountId        = proto.AccountID,
                AdditionalValues = additionalValues,
                ReferenceCode    = proto.ReferenceCode,
                ShippingAddress  = proto.Address,
                NotifyURL        = proto.NotifyURL
            };

            var tx = new Transaction
            {
                Order           = order,
                Payer           = payer,
                Cookie          = proto.Cookie,
                PaymentCountry  = proto.Country,
                Type            = transactionType.Value,
                UserAgent       = proto.UserAgent,
                IPAddress       = proto.IPAddress,
                DeviceSessionID = proto.DeviceSessionID,
            };

            if (proto.ThreeDomainSecure != null)
            {
                tx.ThreeDomainSecure = proto.ThreeDomainSecure;
            }

            return(tx);
        }