public static Payment CreateFuturePayment() { FuturePayment pay = new FuturePayment(); pay.intent = "sale"; CreditCard card = CreditCardTest.GetCreditCard(); List<FundingInstrument> fundingInstruments = new List<FundingInstrument>(); FundingInstrument fundingInstrument = new FundingInstrument(); fundingInstrument.credit_card = card; fundingInstruments.Add(fundingInstrument); Payer payer = new Payer(); payer.payment_method = "credit_card"; payer.funding_instruments = fundingInstruments; List<Transaction> transactionList = new List<Transaction>(); Transaction trans = new Transaction(); trans.amount = AmountTest.GetAmount(); transactionList.Add(trans); pay.transactions = transactionList; pay.payer = payer; Payment paymnt = pay.Create(TestingUtil.GetApiContext()); return paymnt; }
/// <summary> /// Creates a future payment using the specified API context and correlation ID. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> /// <param name="payment">FuturePayment object to be used in creating the PayPal resource.</param> /// <param name="correlationId">(Optional) Application correlation ID</param> /// <returns>A new payment object setup to be used for a future payment.</returns> public static Payment Create(APIContext apiContext, FuturePayment payment, string correlationId = "") { // Validate the arguments to be used in the request ArgumentValidator.ValidateAndSetupAPIContext(apiContext); if (!string.IsNullOrEmpty(correlationId)) { apiContext.HTTPHeaders["PAYPAL-CLIENT-METADATA-ID"] = correlationId; } return Payment.Create(apiContext, payment); }
/// <summary> /// Creates a future payment using the specified API context and correlation ID. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> /// <param name="payment">FuturePayment object to be used in creating the PayPal resource.</param> /// <param name="correlationId">(Optional) Application correlation ID</param> /// <returns>A new payment object setup to be used for a future payment.</returns> public static Payment Create(APIContext apiContext, FuturePayment payment, string correlationId = "") { // Validate the arguments to be used in the request ArgumentValidator.ValidateAndSetupAPIContext(apiContext); if (!string.IsNullOrEmpty(correlationId)) { apiContext.HTTPHeaders["PAYPAL-CLIENT-METADATA-ID"] = correlationId; } return(Payment.Create(apiContext, payment)); }
private Payment CreateFuturePayment(string correlationId, string authorizationCode, string redirectUrl) { Payer payer = new Payer() { payment_method = "paypal" }; var amount = new Amount() { currency = "USD", total = "100", details = new Details() { tax = "15", shipping = "10", subtotal = "75" } }; var redirUrls = new RedirectUrls() { cancel_url = redirectUrl, return_url = redirectUrl }; var itemList = new ItemList() { items = new List<Item>() }; itemList.items.Add(new Item() { name = "Item Name", currency = "USD", price = "15", quantity = "5", sku = "sku" }); var transactionList = new List<Transaction>(); transactionList.Add(new Transaction() { description = "Transaction description.", amount = amount, item_list = itemList }); var authorizationCodeParameters = new CreateFromAuthorizationCodeParameters(); authorizationCodeParameters.setClientId(Configuration.ClientId); authorizationCodeParameters.setClientSecret(Configuration.ClientSecret); authorizationCodeParameters.SetCode(authorizationCode); var apiContext = Configuration.GetAPIContext(); var tokenInfo = Tokeninfo.CreateFromAuthorizationCodeForFuturePayments(apiContext, authorizationCodeParameters); var accessToken = string.Format("{0} {1}", tokenInfo.token_type, tokenInfo.access_token); var futurePaymentApiContext = Configuration.GetAPIContext(accessToken); var futurePayment = new FuturePayment() { intent = "authorize", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; return futurePayment.Create(futurePaymentApiContext, correlationId); }
// #Create Future Payment Using PayPal // This sample code demonstrates how you can process a future payment made using a PayPal account. /// <summary> /// Code example for creating a future payment object. /// </summary> /// <param name="correlationId"></param> /// <param name="authorizationCode"></param> private Payment CreateFuturePayment(string correlationId, string authorizationCode, string redirectUrl) { // ###Payer // A resource representing a Payer that funds a payment // Payment Method // as `paypal` Payer payer = new Payer() { payment_method = "paypal" }; // ###Amount // Let's you specify a payment amount. var amount = new Amount() { currency = "USD", // Total must be equal to sum of shipping, tax and subtotal. total = "100", // ###Details // Let's you specify details of a payment amount. details = new Details() { tax = "15", shipping = "10", subtotal = "75" } }; // # Redirect URLS var redirUrls = new RedirectUrls() { cancel_url = redirectUrl, return_url = redirectUrl }; // ###Items // Items within a transaction. var itemList = new ItemList() { items = new List<Item>() }; itemList.items.Add(new Item() { name = "Item Name", currency = "USD", price = "15", quantity = "5", sku = "sku" }); // ###Transaction // A transaction defines the contract of a // payment - what is the payment for and who // is fulfilling it. var transactionList = new List<Transaction>(); // The Payment creation API requires a list of // Transaction; add the created `Transaction` // to a List transactionList.Add(new Transaction() { description = "Transaction description.", amount = amount, item_list = itemList }); var authorizationCodeParameters = new CreateFromAuthorizationCodeParameters(); authorizationCodeParameters.setClientId(Configuration.ClientId); authorizationCodeParameters.setClientSecret(Configuration.ClientSecret); authorizationCodeParameters.SetCode(authorizationCode); // ### 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. var apiContext = Configuration.GetAPIContext(); var tokenInfo = Tokeninfo.CreateFromAuthorizationCodeForFuturePayments(apiContext, authorizationCodeParameters); var accessToken = string.Format("{0} {1}", tokenInfo.token_type, tokenInfo.access_token); var futurePaymentApiContext = Configuration.GetAPIContext(accessToken); // ###Payment // A FuturePayment Resource var futurePayment = new FuturePayment() { intent = "authorize", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; return futurePayment.Create(futurePaymentApiContext, correlationId); }
/// <summary> /// Creates a future payment using the specified API context and correlation ID. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> /// <param name="correlationId">(Optional) Application correlation ID</param> /// <returns>A new payment object setup to be used for a future payment.</returns> public Payment Create(APIContext apiContext, string correlationId = "") { return(FuturePayment.Create(apiContext, this, correlationId)); }