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()); }
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; }
private Address GetAddress() { Address addrss = new Address(); addrss.line1 = "2211"; addrss.line2 = "N 1st St"; addrss.city = "San Jose"; addrss.phone = "408-456-0392"; addrss.postal_code = "95131"; addrss.state = "California"; addrss.country_code = "US"; return addrss; }
public void AddressConstructorTest() { Address target = new Address(); Assert.IsNotNull(target); }
// ##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"); }
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; }
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; } }