Ejemplo n.º 1
0
        public void CreditCardPay(Address billingaddr, CreditCard cc, Amount amount)
        {
            Transaction transaction = new Transaction();
            transaction.amount = amount;
            transaction.description = "This is the payment transaction description.";

            List<Transaction> transactions = new List<Transaction>();
            transactions.Add(transaction);

            FundingInstrument fundingInstrument = new FundingInstrument();
            fundingInstrument.credit_card = cc;

            List<FundingInstrument> fundingInstruments = new List<FundingInstrument>();
            fundingInstruments.Add(fundingInstrument);

            Payer payer = new Payer();
            payer.funding_instruments = fundingInstruments;
            payer.payment_method = "credit_card";

            Payment payment = new Payment();
            payment.intent = "sale";
            payment.payer  = payer;
            payment.transactions = transactions;

            Payment createdPayment = payment.Create(AccessToken());
        }
Ejemplo n.º 2
0
        public string EfetuarCompra(PessoaFisica pessoaFisica, CreditCard creditCard, int quantidadeFits)
        {
            string valor = (quantidadeFits * valorFits).ToString();

            Dictionary<string, string> payPalConfig = new Dictionary<string, string>();
            payPalConfig.Add("mode", this.mode);

            OAuthTokenCredential tokenCredential = new OAuthTokenCredential(this.clientId, this.clientSecret, payPalConfig);

            string accessToken = tokenCredential.GetAccessToken();

            Address billingAddress = new Address();
            billingAddress.line1 = string.Format("{0} Num {1}",pessoaFisica.Endereco.Rua, pessoaFisica.Endereco.Numero) ;
            billingAddress.city = pessoaFisica.Endereco.Cidade;
            billingAddress.country_code = "BR";
            billingAddress.postal_code = pessoaFisica.Endereco.CEP;
            billingAddress.state = pessoaFisica.Endereco.Estado;

            creditCard.billing_address = billingAddress;

            Details amountDetails = new Details();
            amountDetails.subtotal = valor;
            amountDetails.tax = "0.00";
            amountDetails.shipping = "0.00";

            Amount amount = new Amount();
            amount.total = (quantidadeFits * valorFits).ToString();
            amount.currency = "USD";
            amount.details = amountDetails;

            Transaction transaction = new Transaction();
            transaction.amount = amount;
            transaction.description = string.Format("Este pagamento foi efetuado por {0}, na quantia de {1} fits", pessoaFisica.Nome, quantidadeFits);

            List<Transaction> transactions = new List<Transaction>();
            transactions.Add(transaction);

            FundingInstrument fundingInstrument = new FundingInstrument();
            fundingInstrument.credit_card = creditCard;

            List<FundingInstrument> fundingInstruments = new List<FundingInstrument>();
            fundingInstruments.Add(fundingInstrument);

            Payer payer = new Payer();
            payer.funding_instruments = fundingInstruments;
            payer.payment_method = "credit_card";

            Payment payment = new Payment();
            payment.intent = "sale";
            payment.payer = payer;
            payment.transactions = transactions;

            Payment createdPayment = payment.Create(accessToken);

            return valor;
        }
 public CreditCard CreateCreditCard()
 {
     CreditCard CrdtCard = null;
     CreditCard credCard = new CreditCard();
     credCard.number = TextBoxCreditCardNumber.Text.Trim();
     credCard.cvv2 = TextBoxCreditCardCVV2.Text.Trim();
     credCard.type = DropDownListCreditCardType.SelectedValue.ToString().Trim();
     credCard.expire_month = DropDownListCreditCardExpireMonth.SelectedValue.ToString().Trim();
     credCard.expire_year = DropDownListCreditCardExpireYear.SelectedValue.ToString().Trim();
     CrdtCard = credCard.Create(accessToken);
     return CrdtCard;
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpContext CurrContext = HttpContext.Current;

            // ###CreditCard
            // A resource representing a credit card that can be
            // used to fund a payment.
            CreditCard credtCard = new CreditCard();
            credtCard.expire_month = "11";
            credtCard.expire_year = "2018";
            credtCard.number = "4417119669820331";
            credtCard.type = "visa";

            try
            {
                // ###AccessToken
                // Retrieve the access token from
                // OAuthTokenCredential by passing in
                // ClientID and ClientSecret
                // It is not mandatory to generate Access Token on a per call basis.
                // Typically the access token can be generated once and
                // reused within the expiry window
                string accessToken = new OAuthTokenCredential(ConfigManager.Instance.GetProperty("ClientID"), ConfigManager.Instance.GetProperty("ClientSecret")).GetAccessToken();

                // ### Api Context
                // Pass in a `ApiContext` object to authenticate
                // the call and to send a unique request id
                // (that ensures idempotency). The SDK generates
                // a request id if you do not pass one explicitly.
                APIContext apiContext = new APIContext(accessToken);
                // Use this variant if you want to pass in a request id
                // that is meaningful in your application, ideally
                // a order id.
                // String requestId = Long.toString(System.nanoTime();
                // APIContext apiContext = new APIContext(accessToken, requestId ));

                // ###Save
                // Creates the credit card as a resource
                // in the PayPal vault. The response contains
                // an 'id' that you can use to refer to it
                // in the future payments.
                CreditCard createdCreditCard = credtCard.Create(apiContext);
                CurrContext.Items.Add("ResponseJson", JObject.Parse(createdCreditCard.ConvertToJson()).ToString(Formatting.Indented));
            }
            catch (PayPal.Exception.PayPalException ex)
            {
                CurrContext.Items.Add("Error", ex.Message);
            }

            CurrContext.Items.Add("RequestJson", JObject.Parse(credtCard.ConvertToJson()).ToString(Formatting.Indented));

            Server.Transfer("~/Response.aspx");
        }
 public CreditCard CreateCreditCard(string creditCardType, string creditCardNumber, string creditCardCVV2, string creditCardExpireMonth, string creditCardExpireYear)
 {
     CreditCard card = null;
     CreditCard credCard = new CreditCard();
     credCard.type = creditCardType;
     credCard.number = creditCardNumber;
     credCard.cvv2 = creditCardCVV2;
     credCard.expire_month = System.Convert.ToInt32(creditCardExpireMonth);
     credCard.expire_year = System.Convert.ToInt32(creditCardExpireYear);
     card = credCard.Create(Api);
     return card;
 }
 private CreditCard CreateCreditCard()
 {
     CreditCard card = new CreditCard();
     card.cvv2 = "962";
     card.expire_month = 01;
     card.expire_year = 2015;
     card.first_name = "John";
     card.last_name = "Doe";
     card.number = "4825854086744369";
     card.type = "visa";
     card.payer_id = "008";
     return card.Create(UnitTestUtil.GetApiContext());
 }         
 private CreditCard GetCreditCard()
 {
     CreditCard card = new CreditCard();
     card.cvv2 = "962";
     card.expire_month = 01;
     card.expire_year = 2015;
     card.first_name = "John";
     card.last_name = "Doe";
     card.number = "4825854086744369";
     card.type = "visa";
     card.payer_id = "008";
     card.billing_address = GetAddress();
     return card;
 }
 private CreditCard CreateCreditCard()
 {
     CreditCard card = new CreditCard();
     card.cvv2 = "962";
     card.expire_month = 01;
     card.expire_year = 2015;
     card.first_name = "John";
     card.last_name = "Doe";
     card.number = "4825854086744369";
     card.type = "visa";
     card.state = "New York";
     card.payer_id = "008";
     card.id = "002";
     return card.Create(AccessToken);
 }
        public CreditCard CreateCreditCard()
        {
            CreditCard credCard = new CreditCard();
            credCard.cvv2 = "962";
            credCard.expire_month = "01";
            credCard.expire_year = "2015";
            credCard.first_name = "John";
            credCard.last_name = "Doe";
            credCard.number = "4825854086744369";
            credCard.type = "visa";
            credCard.state = "New York";
            credCard.payer_id = "008";
            credCard.id = "002";

            CreditCard CrdtCard = credCard.Create(AccessToken);
            return CrdtCard;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpContext CurrContext = HttpContext.Current;

            // ###CreditCard
            // A resource representing a credit card that can be
            // used to fund a payment.
            CreditCard credtCard = new CreditCard();
            credtCard.expire_month = 11;
            credtCard.expire_year = 2018;
            credtCard.number = "4417119669820331";
            credtCard.type = "visa";

            try
            {
                 // ### Api Context
                 // Pass in a `APIContext` object to authenticate 
                 // the call and to send a unique request id 
                 // (that ensures idempotency). The SDK generates
                 // a request id if you do not pass one explicitly. 
                  // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext..
                APIContext apiContext = Configuration.GetAPIContext();

                // ###Save
                // Creates the credit card as a resource
                // in the PayPal vault. The response contains
                // an 'id' that you can use to refer to it
                // in the future payments.
                CreditCard createdCreditCard = credtCard.Create(apiContext);
                CurrContext.Items.Add("ResponseJson", JObject.Parse(createdCreditCard.ConvertToJson()).ToString(Formatting.Indented));
            }
            catch (PayPal.Exception.PayPalException ex)
            {
                CurrContext.Items.Add("Error", ex.Message);
            }

            if (credtCard != null)
            {
                CurrContext.Items.Add("RequestJson", JObject.Parse(credtCard.ConvertToJson()).ToString(Formatting.Indented));
            }

            Server.Transfer("~/Response.aspx");
        }
        private string GetSignedInUserCreditCardID(string email)
        {
            string creditCardID = string.Empty;

            CreditCard crdtCard = new CreditCard();
            DataTable datTable = GetUser(email);
            if (datTable != null && datTable.Rows.Count > 0)
            {
                var distinctRows = from DataRow dRow in datTable.Rows
                                   where dRow.Field<string>("email") == email
                                   select new { column1 = dRow["credit_card_id"] };
                if (distinctRows != null)
                {
                    foreach (var row in distinctRows)
                    {
                        creditCardID = Convert.ToString(row.column1);
                        break;
                    }
                }
            }
            return creditCardID;
        }
        // ##Create
        // Sample showing to create a Payment using
        // CreditCard as a FundingInstrument
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpContext CurrContext = HttpContext.Current;

            // ###Items
            // Items within a transaction.
            Item item = new Item();
            item.name = "Item Name";
            item.currency = "USD";
            item.price = "1";
            item.quantity = "5";
            item.sku = "sku";

            List<Item> itms = new List<Item>();
            itms.Add(item);
            ItemList itemList = new ItemList();
            itemList.items = itms;

            // ###Address
            // Base Address object used as shipping or billing
            // address in a payment.
            Address billingAddress = new Address();
            billingAddress.city = "Johnstown";
            billingAddress.country_code = "US";
            billingAddress.line1 = "52 N Main ST";
            billingAddress.postal_code = "43210";
            billingAddress.state = "OH";

            // ###CreditCard
            // A resource representing a credit card that can be
            // used to fund a payment.
            CreditCard crdtCard = new CreditCard();
            crdtCard.billing_address = billingAddress;
            crdtCard.cvv2 = "874";
            crdtCard.expire_month = 11;
            crdtCard.expire_year = 2018;
            crdtCard.first_name = "Joe";
            crdtCard.last_name = "Shopper";
            crdtCard.number = "4417119669820331";
            crdtCard.type = "visa";

            // ###Details
            // Let's you specify details of a payment amount.
            Details details = new Details();
            details.shipping = "1";
            details.subtotal = "5";
            details.tax = "1";

            // ###Amount
            // Let's you specify a payment amount.
            Amount amnt = new Amount();
            amnt.currency = "USD";
            // Total must be equal to sum of shipping, tax and subtotal.
            amnt.total = "7";
            amnt.details = details;

            // ###Transaction
            // A transaction defines the contract of a
            // payment - what is the payment for and who
            // is fulfilling it. 
            Transaction tran = new Transaction();
            tran.amount = amnt;
            tran.description = "This is the payment transaction description.";
            tran.item_list = itemList;

            // The Payment creation API requires a list of
            // Transaction; add the created `Transaction`
            // to a List
            List<Transaction> transactions = new List<Transaction>();
            transactions.Add(tran);

            // ###FundingInstrument
            // A resource representing a Payer's funding instrument.
            // For direct credit card payments, set the CreditCard
            // field on this object.
            FundingInstrument fundInstrument = new FundingInstrument();
            fundInstrument.credit_card = crdtCard;

            // The Payment creation API requires a list of
            // FundingInstrument; add the created `FundingInstrument`
            // to a List
            List<FundingInstrument> fundingInstrumentList = new List<FundingInstrument>();
            fundingInstrumentList.Add(fundInstrument);

            // ###Payer
            // A resource representing a Payer that funds a payment
            // Use the List of `FundingInstrument` and the Payment Method
            // as `credit_card`
            Payer payr = new Payer();
            payr.funding_instruments = fundingInstrumentList;
            payr.payment_method = "credit_card";

            // ###Payment
            // A Payment Resource; create one using
            // the above types and intent as `sale` or `authorize`
            Payment pymnt = new Payment();
            pymnt.intent = "sale";
            pymnt.payer = payr;
            pymnt.transactions = transactions;

            try
            {
                // ### Api Context
                // Pass in a `APIContext` object to authenticate 
                // the call and to send a unique request id 
                // (that ensures idempotency). The SDK generates
                // a request id if you do not pass one explicitly. 
                 // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext..
                APIContext apiContext = Configuration.GetAPIContext();

                // Create a payment using a valid APIContext
                Payment createdPayment = pymnt.Create(apiContext);
                CurrContext.Items.Add("ResponseJson", JObject.Parse(createdPayment.ConvertToJson()).ToString(Formatting.Indented));
            }
            catch (PayPal.Exception.PayPalException ex)
            {
                CurrContext.Items.Add("Error", ex.Message);
            }

            CurrContext.Items.Add("RequestJson", JObject.Parse(pymnt.ConvertToJson()).ToString(Formatting.Indented));

            Server.Transfer("~/Response.aspx");
        }
        // ##Create
        // Sample showing to create a Payment using
        // CreditCard as a FundingInstrument
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpContext CurrContext = HttpContext.Current;

            // ###Address
            // Base Address object used as shipping or billing
            // address in a payment.
            Address billingAddress = new Address();
            billingAddress.city = "Johnstown";
            billingAddress.country_code = "US";
            billingAddress.line1 = "52 N Main ST";
            billingAddress.postal_code = "43210";
            billingAddress.state = "OH";

            // ###CreditCard
            // A resource representing a credit card that can be
            // used to fund a payment.
            CreditCard crdtCard = new CreditCard();
            crdtCard.billing_address = billingAddress;
            crdtCard.cvv2 = "874";
            crdtCard.expire_month = 11;
            crdtCard.expire_year = 2018;
            crdtCard.first_name = "Joe";
            crdtCard.last_name = "Shopper";
            crdtCard.number = "4417119669820331";
            crdtCard.type = "visa";

            // ###Details
            // Let's you specify details of a payment amount.
            Details details = new Details();
            details.shipping = "1";
            details.subtotal = "5";
            details.tax = "1";

            // ###Amount
            // Let's you specify a payment amount.
            Amount amnt = new Amount();
            amnt.currency = "USD";
            // Total must be equal to sum of shipping, tax and subtotal.
            amnt.total = "7";
            amnt.details = details;

            // ###Transaction
            // A transaction defines the contract of a
            // payment - what is the payment for and who
            // is fulfilling it. Transaction is created with
            // a `Payee` and `Amount` types
            Transaction tran = new Transaction();
            tran.amount = amnt;
            tran.description = "This is the payment transaction description.";

            // The Payment creation API requires a list of
            // Transaction; add the created `Transaction`
            // to a List
            List<Transaction> transactions = new List<Transaction>();
            transactions.Add(tran);

            // ###FundingInstrument
            // A resource representing a Payeer's funding instrument.
            // Use a Payer ID (A unique identifier of the payer generated
            // and provided by the facilitator. This is required when
            // creating or using a tokenized funding instrument)
            // and the `CreditCardDetails`
            FundingInstrument fundInstrument = new FundingInstrument();
            fundInstrument.credit_card = crdtCard;

            // The Payment creation API requires a list of
            // FundingInstrument; add the created `FundingInstrument`
            // to a List
            List<FundingInstrument> fundingInstrumentList = new List<FundingInstrument>();
            fundingInstrumentList.Add(fundInstrument);

            // ###Payer
            // A resource representing a Payer that funds a payment
            // Use the List of `FundingInstrument` and the Payment Method
            // as 'credit_card'
            Payer payr = new Payer();
            payr.funding_instruments = fundingInstrumentList;
            payr.payment_method = "credit_card";

            // ###Payment
            // A Payment Resource; create one using
            // the above types and intent as `sale`
            Payment pymnt = new Payment();
            pymnt.intent = "sale";
            pymnt.payer = payr;
            pymnt.transactions = transactions;

            try
            {
                // ###AccessToken
                // Retrieve the access token from
                // OAuthTokenCredential by passing in
                // ClientID and ClientSecret
                // It is not mandatory to generate Access Token on a per call basis.
                // Typically the access token can be generated once and
                // reused within the expiry window
                string accessToken = new OAuthTokenCredential(ConfigManager.Instance.GetProperties()["ClientID"], ConfigManager.Instance.GetProperties()["ClientSecret"]).GetAccessToken();

                // ### Api Context
                // Pass in a `ApiContext` object to authenticate
                // the call and to send a unique request id
                // (that ensures idempotency). The SDK generates
                // a request id if you do not pass one explicitly.
                APIContext apiContext = new APIContext(accessToken);
                // Use this variant if you want to pass in a request id
                // that is meaningful in your application, ideally
                // a order id.
                // String requestId = Long.toString(System.nanoTime();
                // APIContext apiContext = new APIContext(accessToken, requestId ));

                // Create a payment by posting to the APIService
                // using a valid AccessToken
                // The return object contains the status;
                Payment createdPayment = pymnt.Create(apiContext);
                CurrContext.Items.Add("ResponseJson", JObject.Parse(createdPayment.ConvertToJson()).ToString(Formatting.Indented));
            }
            catch (PayPal.Exception.PayPalException ex)
            {
                CurrContext.Items.Add("Error", ex.Message);
            }
            CurrContext.Items.Add("RequestJson", JObject.Parse(pymnt.ConvertToJson()).ToString(Formatting.Indented));

            Server.Transfer("~/Response.aspx");
        }
Ejemplo n.º 14
0
        public static CreditCard SaveCreditCard(APIContext apiContext)
        {
            // ###CreditCard
            // A resource representing a credit card that can be
            // used to fund a payment.
            CreditCard credtCard = new CreditCard();
            credtCard.expire_month = 11;
            credtCard.expire_year = 2018;
            credtCard.number = "4417119669820331";
            credtCard.type = "visa";

            // ###Save
            // Creates the credit card as a resource
            // in the PayPal vault. The response contains
            // an 'id' that you can use to refer to it
            // in the future payments.
            CreditCard createdCreditCard = credtCard.Create(apiContext);
            return createdCreditCard;
        }
 public CreditCard CreateCreditCard(ProfileModel model)
 {
     CreditCard card = null;
     CreditCard cardCredit = new CreditCard();
     cardCredit.number = model.NewCreditCardNumber.Trim();
     cardCredit.type = model.NewCreditCardType.Trim();
     cardCredit.cvv2 = model.NewCreditCardCVV2.Trim();
     cardCredit.expire_month = Convert.ToInt32(model.NewCreditCardExpireMonth.Trim());
     cardCredit.expire_year = Convert.ToInt32(model.NewCreditCardExpireYear.Trim());
     card = cardCredit.Create(Api);
     return card;
 }
        public HttpResponseMessage ComprarFits2([FromBody]ComprarFitsApiModel model)
        {
            Util.PayPalNegocio paypalNegocio = new Util.PayPalNegocio("AUoYdBAqgl5mugEOu-xrxNeLj0DW2CohcYODtyxzsozi-me48ymybDi6dtw2",
              "ELyImxCvpvxoiFRyfqzScMZbfo84f2Au4l-TJX78ymKuHskG_pDAcJHHt3uf", "sandbox", 5);

            CreditCard creditCard = new CreditCard();
            creditCard.number = model.NumeroCartao;
            creditCard.type = model.TipoCartao;
            creditCard.expire_month = Convert.ToInt32(model.Mes);
            creditCard.expire_year = Convert.ToInt32(model.Ano);
            creditCard.cvv2 = Convert.ToInt32(model.Cvv);

            var pessoaFisica = unityOfWork.PessoaFisicaNegocio.BuscarPorChave(model.ChavePessoaFisica);
            //comprar
            var valor = paypalNegocio.EfetuarCompra(pessoaFisica,
                creditCard, model.QuantidadeFits);
            //CreditarFits
            unityOfWork.PessoaFisicaNegocio.CreditarFits(pessoaFisica, model.QuantidadeFits, valor);

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Ejemplo n.º 17
0
 public void CreditCardConstructorTest()
 {
     CreditCard target = new CreditCard();
     Assert.IsNotNull(target);
 }
Ejemplo n.º 18
0
        private CreditCard CreateCreditCard(ProcessPaymentRequest request)
        {
            var card = new CreditCard
            {
                number = request.Parameters[PayPalConstants.CreditCardNumber],
                type = request.Parameters[PayPalConstants.CreditCardType],
                expire_month = Convert.ToInt32(request.Parameters[PayPalConstants.CreditCardExpireMonth]),
                expire_year = Convert.ToInt32(request.Parameters[PayPalConstants.CreditCardExpireYear]),
                cvv2 = request.Parameters[PayPalConstants.CreditCardCvv2]
            };

            // If the website don't pass in customer info,
            // then we try to fill these info automatically
            if (request.Payment.PaymentTarget.Type == PaymentTargetTypes.Order)
            {
                var orderId = Convert.ToInt32(request.Payment.PaymentTarget.Id);
                var order = _orderService.GetById(orderId);

                card.first_name = order.Customer.FirstName;
                card.last_name = order.Customer.LastName;

                // TODO: Add billing address
            }

            return card;
        }
        private string GetAuthorizationId(string accessToken)
        {
            // ###Address
            // Base Address object used as shipping or billing
            // address in a payment.
            Address billingAddress = new Address();
            billingAddress.city = "Johnstown";
            billingAddress.country_code = "US";
            billingAddress.line1 = "52 N Main ST";
            billingAddress.postal_code = "43210";
            billingAddress.state = "OH";

            // ###CreditCard
            // A resource representing a credit card that can be
            // used to fund a payment.
            CreditCard crdtCard = new CreditCard();
            crdtCard.billing_address = billingAddress;
            crdtCard.cvv2 = "874";
            crdtCard.expire_month = 11;
            crdtCard.expire_year = 2018;
            crdtCard.first_name = "Joe";
            crdtCard.last_name = "Shopper";
            crdtCard.number = "4417119669820331";
            crdtCard.type = "visa";

            // ###Details
            // Let's you specify details of a payment amount.
            Details details = new Details();
            details.shipping = "0.03";
            details.subtotal = "107.41";
            details.tax = "0.03";

            // ###Amount
            // Let's you specify a payment amount.
            Amount amnt = new Amount();
            amnt.currency = "USD";
            // Total must be equal to sum of shipping, tax and subtotal.
            amnt.total = "107.47";
            amnt.details = details;

            // ###Transaction
            // A transaction defines the contract of a
            // payment - what is the payment for and who
            // is fulfilling it. Transaction is created with
            // a `Payee` and `Amount` types
            Transaction tran = new Transaction();
            tran.amount = amnt;
            tran.description = "This is the payment transaction description.";

            // The Payment creation API requires a list of
            // Transaction; add the created `Transaction`
            // to a List
            List<Transaction> transactions = new List<Transaction>();
            transactions.Add(tran);

            // ###FundingInstrument
            // A resource representing a Payeer's funding instrument.
            // Use a Payer ID (A unique identifier of the payer generated
            // and provided by the facilitator. This is required when
            // creating or using a tokenized funding instrument)
            // and the `CreditCardDetails`
            FundingInstrument fundInstrument = new FundingInstrument();
            fundInstrument.credit_card = crdtCard;

            // The Payment creation API requires a list of
            // FundingInstrument; add the created `FundingInstrument`
            // to a List
            List<FundingInstrument> fundingInstrumentList = new List<FundingInstrument>();
            fundingInstrumentList.Add(fundInstrument);

            // ###Payer
            // A resource representing a Payer that funds a payment
            // Use the List of `FundingInstrument` and the Payment Method
            // as 'credit_card'
            Payer payr = new Payer();
            payr.funding_instruments = fundingInstrumentList;
            payr.payment_method = "credit_card";

            // ###Payment
            // A Payment Resource; create one using
            // the above types and intent as `sale`
            Payment pymnt = new Payment();
            pymnt.intent = "authorize";
            pymnt.payer = payr;
            pymnt.transactions = transactions;

            // Create a payment by posting to the APIService
            // using a valid AccessToken
            // The return object contains the status;
            Payment createdPayment = pymnt.Create(accessToken);

            return createdPayment.transactions[0].related_resources[0].authorization.id;
        }
Ejemplo n.º 20
0
 public CreditCard GetCreditCard()
 {
     CreditCard credCard = new CreditCard();
     credCard.cvv2 = "962";
     credCard.expire_month = "01";
     credCard.expire_year = "2015";
     credCard.first_name = "John";
     credCard.last_name = "Doe";
     credCard.number = "4825854086744369";
     credCard.type = "visa";
     credCard.state = "New York";
     credCard.payer_id = "008";
     credCard.id = "002";
     credCard.billing_address = GetAddress();
     return credCard;
 }
Ejemplo n.º 21
0
        private Payment CreatePaymentCreditCard()
        {
            //Create Payment With Credit Card
            try
            {
                Transaction tran = new Transaction();

                //Redirect Url
                RedirectUrls red = new RedirectUrls();
                red.return_url = "";
                red.cancel_url = "";

                //Detail
                Details det = new Details();
                det.shipping = "0";
                det.tax = "0";
                det.fee = "0";

                //Address
                Address billingAddress = new Address();
                billingAddress.city = "Johnstown";
                billingAddress.country_code = "US";
                billingAddress.line1 = "52 N Main ST";
                billingAddress.postal_code = "43210";
                billingAddress.state = "OH";

                //CreditCard
                CreditCard creditCard = new CreditCard();
                creditCard.number = "4417119669820331";
                creditCard.type = "visa";
                creditCard.expire_month = 11;
                creditCard.expire_year = 2018;
                creditCard.cvv2 = "111";
                creditCard.first_name = "TestF";
                creditCard.last_name = "TestL";
                creditCard.billing_address = billingAddress;

                //Create item
                ItemList ItemList = new ItemList();
                ItemList.items = new List<Item>();
                ItemList.items.Add(new Item { name = "A", currency = "USD", price = "10", quantity = "1", sku = "1" });
                ItemList.items.Add(new Item { name = "B", currency = "USD", price = "20", quantity = "2", sku = "1" });
                ItemList.items.Add(new Item { name = "C", currency = "USD", price = "50", quantity = "3", sku = "1" });
                ItemList.items.Add(new Item { name = "D", currency = "USD", price = "100", quantity = "4", sku = "1" });
                //tran.item_list = ItemList;

                //Create Amount
                Amount amnt = new Amount();
                amnt.currency = "USD";
                amnt.total = "600";
                //amnt.details = det;
                tran.amount = amnt;

                //Transaction
                tran.description = "TestPaypal Sandbox";
                List<Transaction> transactions = new List<Transaction>();
                transactions.Add(tran);

                //Instrument
                FundingInstrument fundingInstrument = new FundingInstrument();
                fundingInstrument.credit_card = creditCard;

                List<FundingInstrument> fundingInstruments = new List<FundingInstrument>();
                fundingInstruments.Add(fundingInstrument);

                Payer payer = new Payer();
                payer.payment_method = "credit_card";
                payer.funding_instruments = fundingInstruments;

                //Payment
                Payment payment = new Payment();
                payment.intent = "sale";
                payment.payer = payer;
                payment.transactions = transactions;
                payment.redirect_urls = red;

                Payment createdPayment = payment.Create(Api);

                return createdPayment;
            }
            catch (PayPal.Exception.PayPalException ex)
            {
                var a = ex.Message;
                return null;
            }
        }
 private int GetSignedInUserLastInsertedOrderID(int userID)
 {
     int orderID = 0;
     CreditCard crdtCard = new CreditCard();
     DataTable datTable = GetOrders(userID);
     if (datTable != null && datTable.Rows.Count > 0)
     {
         var distinctRows = from DataRow dRow in datTable.Rows
                            select new { column1 = dRow["id"] };
         if (distinctRows != null)
         {
             foreach (var row in distinctRows)
             {
                 orderID = Convert.ToInt32(row.column1);
                 break;
             }
         }
     }
     return orderID;
 }
        public ActionResult ComprarFits(ComprarFitsViewModel model)
        {
            Util.PayPalNegocio paypalNegocio = new Util.PayPalNegocio("AUoYdBAqgl5mugEOu-xrxNeLj0DW2CohcYODtyxzsozi-me48ymybDi6dtw2",
              "ELyImxCvpvxoiFRyfqzScMZbfo84f2Au4l-TJX78ymKuHskG_pDAcJHHt3uf", "sandbox", 5);

            var usuario = (UsuarioLogadoModel)Session["usuario"];

            CreditCard creditCard = new CreditCard();
            creditCard.number = model.NumeroCartao;
            creditCard.type = model.TipoCartao;
            creditCard.expire_month = Convert.ToInt32(model.Mes);
            creditCard.expire_year = Convert.ToInt32(model.Ano);
            creditCard.first_name = usuario.Email;
            creditCard.cvv2 = Convert.ToInt32(model.Cvv);

            if (usuario.IsPessoaFisica)
            {
                var pessoaFisica = unityOfWork.PessoaFisicaNegocio.BuscarPorChave(usuario.Chave);
                //realizou pagamento
                var valor = paypalNegocio.EfetuarCompra(pessoaFisica,
                    creditCard, model.QuantidadeFits);
                //creditou fits
                unityOfWork.PessoaFisicaNegocio.CreditarFits(pessoaFisica, model.QuantidadeFits, valor);
                unityOfWork.Commit();
            }
            else
                ExibirMensagemErro("Compra não autorizada para usuários que sejam pessoa jurídica.");

            ExibirMensagemSucesso("Compra realizada com sucesso.");
            return RedirectToAction("ComprarFits");
        }