Пример #1
0
 private Payment GetFuturePayment()
 {
     FuturePayment pay = new FuturePayment();
     pay.intent = "sale";
     CreditCard card = 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 = GetAmount();
     transactionList.Add(trans);
     pay.transactions = transactionList;
     pay.payer = payer;
     Payment paymnt = pay.Create(UnitTestUtil.GetApiContext());
     return paymnt;
 }
        /// <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"
            };

            // ###Details
            // Let's you specify details of a payment amount.
            Details details = new Details()
            {
                tax = "15",
                shipping = "10",
                subtotal = "75"
            };

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

            // # 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);

		    var apiContext = new APIContext();
            apiContext.Config = Configuration.GetConfig();

            var tokenInfo = Tokeninfo.CreateFromAuthorizationCodeForFuturePayments(apiContext, authorizationCodeParameters);
            var accessToken = string.Format("{0} {1}", tokenInfo.token_type, tokenInfo.access_token);

            // ###Payment
            // A FuturePayment Resource
            this.futurePayment = new FuturePayment()
            {
                intent = "authorize",
                payer = payer,
                transactions = transactionList,
                redirect_urls = redirUrls
            };
            return this.futurePayment.Create(accessToken, correlationId);
        }