APIContext is used when making HTTP calls to the PayPal REST API.
Esempio n. 1
1
        /// <summary>
        /// Create a payout batch resource by passing a sender_batch_header and an items array to the request URI. The sender_batch_header contains payout parameters that describe the handling of a batch resource while the items array conatins payout items.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="payout">Payout object to be created as a PayPal resource.</param>
        /// <param name="syncMode">A value of true will provide an immediate, synchronous response. Without this query keyword or if the value is false, the response will be a background batch mode.</param>
        /// <returns>PayoutCreateResponse</returns>
        public static PayoutBatch Create(APIContext apiContext, Payout payout, bool syncMode = false)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(syncMode, "syncMode");

            var queryParameters = new QueryParameters();
            queryParameters["sync_mode"] = syncMode.ToString();

            // Configure and send the request
            var resourcePath = "v1/payments/payouts" + queryParameters.ToUrlFormattedString();
            return PayPalResource.ConfigureAndExecute<PayoutBatch>(apiContext, HttpMethod.POST, resourcePath, payout.ConvertToJson());
        }
Esempio n. 2
0
 public PaypalProcessor()
 {
     // Authenticate with PayPal
     var config = ConfigManager.Instance.GetProperties();
     var accessToken = new OAuthTokenCredential(config).GetAccessToken();
     _apiContext = new APIContext(accessToken);
 }
Esempio n. 3
0
 public void APIContextResetRequestIdTest()
 {
     var apiContext = new APIContext();
     var originalRequestId = apiContext.RequestId;
     apiContext.ResetRequestId();
     Assert.AreNotEqual(originalRequestId, apiContext.RequestId);
 }
Esempio n. 4
0
 public static PayoutBatch CreateSingleSynchronousPayoutBatch(APIContext apiContext)
 {
     return Payout.Create(apiContext, new Payout
     {
         sender_batch_header = new PayoutSenderBatchHeader
         {
             sender_batch_id = "batch_" + System.Guid.NewGuid().ToString().Substring(0, 8),
             email_subject = "You have a Payout!"
         },
         items = new List<PayoutItem>
         {
             new PayoutItem
             {
                 recipient_type = PayoutRecipientType.EMAIL,
                 amount = new Currency
                 {
                     value = "1.0",
                     currency = "USD"
                 },
                 note = "Thanks for the payment!",
                 sender_item_id = "2014031400023",
                 receiver = "*****@*****.**"
             }
         }
     },
     true);
 }
Esempio n. 5
0
 public static APIContext GetAPIContext()
 {
     // return apicontext object by invoking it with the accesstoken
     APIContext apiContext = new APIContext(GetAccessToken());
     apiContext.Config = GetConfig();
     return apiContext;
 }
Esempio n. 6
0
 public APIContext GetGetAPIContext()
 {
     var config = ConfigManager.Instance.GetProperties();
     string accessToken = new OAuthTokenCredential(config["clientId"], config["clientSecret"], config).GetAccessToken();
     APIContext apiContext = new APIContext(accessToken);
     apiContext.Config = config;
     return apiContext;
 }
        public APIContext GetApiContext(string accessToken = "")
        {
            var apiContext = new APIContext(string.IsNullOrEmpty(accessToken)
                ? GetAccessToken()
                : accessToken) { Config = GetConfig() };

            return apiContext;
        }
Esempio n. 8
0
        private Payment CreatePaymentInternal(APIContext apiContext, string redirectUrl, double amountValue)
        {
            var amountStringValue = string.Format(CultureInfo.InvariantCulture, "{0:0.00}", amountValue);
            var invoiceNumber = Convert.ToString((new Random()).Next(100000));
            //similar to credit card create itemlist and add item objects to it
            var itemList = new ItemList { items = new List<Item>() };

            itemList.items.Add(new Item
            {
                name = "Socialforce credit amount",
                currency = "USD",
                price = amountStringValue,
                quantity = "1",
                sku = "sku"
            });

            var payer = new Payer { payment_method = "paypal" };

            // Configure Redirect Urls here with RedirectUrls object
            var redirUrls = new RedirectUrls
            {
                cancel_url = redirectUrl,
                return_url = redirectUrl
            };

            // similar as we did for credit card, do here and create details object
            //var details = new Details
            //{
            //    subtotal = amountValue.ToString(CultureInfo.InvariantCulture)
            //};

            // similar as we did for credit card, do here and create amount object
            var amount = new Amount
            {
                currency = "USD",
                total = amountStringValue, // Total must be equal to sum of shipping, tax and subtotal.
                //details = details
            };

            var transactionList = new List<Transaction>();

            transactionList.Add(new Transaction
            {
                description = "Gigbucket credit amount",
                invoice_number = invoiceNumber,
                amount = amount,
                item_list = itemList
            });

            var payment = new Payment
            {
                intent = "sale",
                payer = payer,
                transactions = transactionList,
                redirect_urls = redirUrls
            };
            return payment.Create(apiContext);
        }
Esempio n. 9
0
        /// <summary>
        /// Create a web experience profile by passing the name of the profile and other profile details in the request JSON to the request URI.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="webProfile">WebProfile object to be created as a PayPal resource.</param>
        /// <returns>CreateProfileResponse</returns>
        public static CreateProfileResponse Create(APIContext apiContext, WebProfile webProfile)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);

            // Configure and send the request
            var resourcePath = "v1/payment-experience/web-profiles";
            return PayPalResource.ConfigureAndExecute<CreateProfileResponse>(apiContext, HttpMethod.POST, resourcePath, webProfile.ConvertToJson());
        }
Esempio n. 10
0
        /// <summary>
        /// Retrieves the master list of available Webhooks events-types resources for any webhook to subscribe to.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <returns>EventTypeList</returns>
        public static WebhookEventTypeList AvailableEventTypes(APIContext apiContext)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);

            // Configure and send the request
            var resourcePath = "v1/notifications/webhooks-event-types";
            return PayPalResource.ConfigureAndExecute<WebhookEventTypeList>(apiContext, HttpMethod.GET, resourcePath);
        }
 // Returns APIContext object
 public static APIContext GetApiContext()
 {
     // Pass in a `APIContext` object to authenticate the call with a unique order id
      var apiContext = new APIContext(GetAccessToken())
      {
          Config = GetConfig()
      };
      return apiContext;
 }
Esempio n. 12
0
        /// <summary>
        /// Creates the Webhook for the application associated with the access token.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="webhook"><seealso cref="Webhook"/> object to be created.</param>
        /// <returns>Webhook</returns>
        public static Webhook Create(APIContext apiContext, Webhook webhook)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);

            // Configure and send the request
            var resourcePath = "v1/notifications/webhooks";
            return PayPalResource.ConfigureAndExecute<Webhook>(apiContext, HttpMethod.POST, resourcePath, webhook.ConvertToJson());
        }
Esempio n. 13
0
 public void APIContextValidConstructorWithAccessTokenTest()
 {
     var apiContext = new APIContext("abc");
     Assert.IsFalse(string.IsNullOrEmpty(apiContext.RequestId));
     Assert.IsFalse(apiContext.MaskRequestId);
     Assert.AreEqual("abc", apiContext.AccessToken);
     Assert.IsNull(apiContext.Config);
     Assert.IsNull(apiContext.HTTPHeaders);
     Assert.IsNotNull(apiContext.SdkVersion);
 }
Esempio n. 14
0
        /// <summary>
        /// Obtain the payment instruction resource for the given identifier.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="paymentId">Identifier of the Payment instruction resource to obtain the data for.</param>
        /// <returns>PaymentInstruction</returns>
        public static PaymentInstruction Get(APIContext apiContext, string paymentId)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(paymentId, "paymentId");

            // Configure and send the request
            var pattern = "v1/payments/payments/payment/{0}/payment-instruction";
            var resourcePath = SDKUtil.FormatURIPath(pattern, new object[] { paymentId });
            return PayPalResource.ConfigureAndExecute<PaymentInstruction>(apiContext, HttpMethod.GET, resourcePath);
        }
Esempio n. 15
0
 /// <summary>
 /// Helper method for validating and setting up an APIContext object in preparation for it being used when sending an HTTP request.
 /// </summary>
 /// <param name="apiContext">APIContext used for API calls.</param>
 public static void ValidateAndSetupAPIContext(APIContext apiContext)
 {
     ArgumentValidator.Validate(apiContext, "APIContext");
     ArgumentValidator.Validate(apiContext.AccessToken, "AccessToken");
     if (apiContext.HTTPHeaders == null)
     {
         apiContext.HTTPHeaders = new Dictionary<string, string>();
     }
     apiContext.HTTPHeaders[BaseConstants.ContentTypeHeader] = BaseConstants.ContentTypeHeaderJson;
     apiContext.SdkVersion = new SDKVersion();
 }
Esempio n. 16
0
        /// <summary>
        /// Obtain the Refund transaction resource for the given identifier.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="refundId">Identifier of the Refund Transaction Resource to obtain the data for.</param>
        /// <returns>Refund</returns>
        public static Refund Get(APIContext apiContext, string refundId)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(refundId, "refundId");

            // Configure and send the request
            var pattern = "v1/payments/refund/{0}";
            var resourcePath = SDKUtil.FormatURIPath(pattern, new object[] { refundId });
            return PayPalResource.ConfigureAndExecute<Refund>(apiContext, HttpMethod.GET, resourcePath);
        }
Esempio n. 17
0
        /// <summary>
        /// Retrieves the Webhook identified by webhook_id for the application associated with access token.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="webhookId">Identifier of the webhook</param>
        /// <returns>Webhook</returns>
        public static Webhook Get(APIContext apiContext, string webhookId)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(webhookId, "webhookId");

            // Configure and send the request
            var pattern = "v1/notifications/webhooks/{0}";
            var resourcePath = SDKUtil.FormatURIPath(pattern, new object[] { webhookId });
            return PayPalResource.ConfigureAndExecute<Webhook>(apiContext, HttpMethod.GET, resourcePath);
        }
Esempio n. 18
0
        /// <summary>
        /// Cancels the unclaimed payment using the items id passed in the request URI.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="payoutItemId">Payouts generated payout_item_id to obtain status.</param>
        /// <returns>PayoutItemDetails</returns>
        public static PayoutItemDetails Cancel(APIContext apiContext, string payoutItemId)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(payoutItemId, "payoutItemId");

            // Configure and send the request
            var pattern = "v1/payments/payouts-item/{0}/cancel";
            var resourcePath = SDKUtil.FormatURIPath(pattern, new object[] { payoutItemId });
            return PayPalResource.ConfigureAndExecute<PayoutItemDetails>(apiContext, HttpMethod.POST, resourcePath);
        }
 // Returns APIContext object
 public static APIContext GetAPIContext(string accessToken = "")
 {
     // 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. 
     var apiContext = new APIContext(string.IsNullOrEmpty(accessToken) ?
         GetAccessToken() : accessToken);
     apiContext.Config = GetConfig();
     
     return apiContext;
 }
Esempio n. 20
0
        /// <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);
        }
Esempio n. 21
0
        /// <summary>
        /// Deletes a webhook, by ID.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="webhookId">The ID of the webhook to delete.</param>
        public static void Delete(APIContext apiContext, string webhookId)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(webhookId, "webhookId");

            // Configure and send the request
            apiContext.MaskRequestId = true;
            var pattern = "v1/notifications/webhooks/{0}";
            var resourcePath = SDKUtil.FormatURIPath(pattern, new object[] { webhookId });
            PayPalResource.ConfigureAndExecute(apiContext, HttpMethod.DELETE, resourcePath);
        }
        /// <summary>
        /// Connect in PayPal and generate the TOKEN.
        /// </summary>
        protected void Connect()
        {
            config = ConfigManager.Instance.GetProperties();
            accessToken = new OAuthTokenCredential(config).GetAccessToken();

            context = new APIContext(accessToken);

            // Define any HTTP headers to be used in HTTP requests made with this APIContext object
            if (context.HTTPHeaders == null)
                context.HTTPHeaders = new Dictionary<String, String>();

            context.HTTPHeaders["XX-Company"] = "ChickenScratch";
        }
Esempio n. 23
0
        public Payment CreatePayment(APIContext apiContext, List<Transaction> paypalTransactions, RedirectUrls redirectUrls)
        {

            var payment = Payment.Create(apiContext, new Payment()
            {
                intent = "sale",
                payer = new Payer
                {
                    payment_method = "paypal"
                },
                transactions = paypalTransactions,
                redirect_urls = redirectUrls
            });
            return payment;
        }
Esempio n. 24
0
        // Returns APIContext object
        public static APIContext GetAPIContext(string accessToken = "")
        {
            // ### 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. 
            var apiContext = new APIContext(string.IsNullOrEmpty(accessToken) ? GetAccessToken() : accessToken);
            apiContext.Config = GetConfig();

            // 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(GetAccessToken(), requestId ));

            return apiContext;
        }
        protected override void RunSample()
        {
            string accessToken = new OAuthTokenCredential("EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM", "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM", Configuration.GetConfig()).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.
            // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.
            var apiContext = new APIContext(accessToken);

            var webhookId = "9XL90610J3647323C";

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Verify received webhook event");
            #endregion

            // Construct a `VerifyWebhookSignature` and assign its properties from the headers received in your webhook event.
            var signatureVerification = new PayPal.Api.VerifyWebhookSignature
            {
                auth_algo = headers["Paypal-Auth-Algo"],
                cert_url = headers["Paypal-Cert-Url"],
                transmission_id = headers["Paypal-Transmission-Id"],
                transmission_sig = headers["Paypal-Transmission-Sig"],
                transmission_time = headers["Paypal-Transmission-Time"],
                webhook_id = webhookId,
                webhook_event = JsonFormatter.ConvertFromJson<WebhookEvent>(requestBody)
            };

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Verify the received webhook Event", signatureVerification);
            #endregion

            // Call the `Post` method on your `VerifyWebhookSignature` object to verify the Webhook event was actually sent by PayPal.
            var signatureVerificationResponse = signatureVerification.Post(apiContext);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordResponse(signatureVerificationResponse);
            #endregion
        }
Esempio n. 26
0
        public void UserInfoGetUserInfoWithRefreshTokenTest()
        {
            try
            {
                var config = ConfigManager.Instance.GetProperties();
                config[BaseConstants.ClientId] = "AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS";
                config[BaseConstants.ClientSecret] = "EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL";
                var apiContext = new APIContext() { Config = config };

                // Using the refresh token, first get an access token.
                var tokenInfo = new Tokeninfo();
                tokenInfo.refresh_token = "W1JmxG-Cogm-4aSc5Vlen37XaQTj74aQcQiTtXax5UgY7M_AJ--kLX8xNVk8LtCpmueFfcYlRK6UgQLJ-XHsxpw6kZzPpKKccRQeC4z2ldTMfXdIWajZ6CHuebs";
                var refreshTokenParameters = new CreateFromRefreshTokenParameters();
                var token = tokenInfo.CreateFromRefreshToken(apiContext, refreshTokenParameters);
                this.RecordConnectionDetails();

                var userInfoParameters = new UserinfoParameters();
                userInfoParameters.SetAccessToken(token.access_token);

                // Get the user information.
                var userInfo = PayPal.Api.OpenIdConnect.Userinfo.GetUserinfo(userInfoParameters);
                this.RecordConnectionDetails();

                Assert.AreEqual("account", userInfo.family_name);
                Assert.AreEqual("facilitator account", userInfo.name);
                Assert.AreEqual("facilitator", userInfo.given_name);
                Assert.AreEqual("BUSINESS", userInfo.account_type);
                Assert.AreEqual("https://www.paypal.com/webapps/auth/identity/user/jWZav5QbA94DNm5FzsNOsq88y4QYrRvu4KLfUydcJqU", userInfo.user_id);
                Assert.IsTrue(userInfo.verified_account.Value);
                Assert.AreEqual("en_US", userInfo.locale);
            }
            catch(ConnectionException)
            {
                this.RecordConnectionDetails(false);
                throw;
            }
        }
Esempio n. 27
0
 /// <summary>
 /// Delete the Credit Card resource for the given identifier.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 public void Delete(APIContext apiContext)
 {
     CreditCard.Delete(apiContext, this.id);
 }
Esempio n. 28
0
        private Payment CreatePayment(PayPal.Api.APIContext apiContext, string redirectUrl, BuyingVM buyingVM)
        {
            //create itemlist and add item objects to it

            var itemList = new ItemList()
            {
                items = new List <Item>()
            };

            // Adding Item Details like name, currency, price etc
            itemList.items.Add(new Item()
            {
                name     = buyingVM.ReportTitle.ToString(), // buyingVM.ReportTitle,
                currency = "USD",
                price    = buyingVM.Price.ToString(),       //(buyingVM.Price).ToString(),
                quantity = "1",
                sku      = "sku"
            });
            var transaction = new Transaction()
            {
                amount = new Amount()
                {
                    currency = "USD",
                    total    = buyingVM.Price.ToString()
                },
                item_list = itemList,

                description = "This is the payment transaction description.",

                invoice_number = GetRandomInvoiceNumber()
            };

            var payer = new Payer()
            {
                payment_method = "paypal"
            };


            var redirUrls = new RedirectUrls()
            {
                cancel_url = redirectUrl + "&Cancel=true",
                return_url = redirectUrl
            };


            this.payment = new Payment()
            {
                intent       = "sale",
                payer        = payer,
                transactions = new List <Transaction>()
                {
                    transaction
                },
                redirect_urls = redirUrls
            };

            return(this.payment.Create(apiContext));

            /*
             * //create itemlist and add item objects to it
             * //var pricedemo = 10;
             * var itemList = new ItemList()
             * {
             *  items = new List<Item>()
             * };
             * // Adding Item Details like name, currency, price etc
             * itemList.items.Add(new Item()
             * {
             *  name = "Global 3-Methyl-1",// buyingVM.ReportTitle,
             *  currency = "USD",
             *  price = "1",//(buyingVM.Price).ToString(),
             *  quantity = "1",
             *  sku = "sku"
             * });
             *
             * var payer = new Payer()
             * {
             *  payment_method = "paypal"
             * };
             * // Configure Redirect Urls here with RedirectUrls object
             * var redirUrls = new RedirectUrls()
             * {
             *  cancel_url = redirectUrl + "&Cancel=true",
             *  return_url = redirectUrl
             * };
             * // Adding Tax, shipping and Subtotal details
             * var details = new Details()
             * {
             *  tax = "1",
             *  shipping = "1",
             *  subtotal = "1"
             * };
             * //Final amount with details
             * var amount = new Amount()
             * {
             *  currency = "USD",
             *  total ="1",// pricedemo.ToString(),//buyingVM.Price.ToString(), // Total must be equal to sum of tax, shipping and subtotal.
             *  details = details
             * };
             * var transactionList = new List<Transaction>();
             * // Adding description about the transaction
             * transactionList.Add(new Transaction()
             * {
             *  description = "Transaction description",
             *  invoice_number = "your generated invoice number", //Generate an Invoice No
             *  amount = amount,
             *  item_list = itemList
             * });
             * this.payment = new Payment()
             * {
             *  intent = "sale",
             *  payer = payer,
             *  transactions = transactionList,
             *  redirect_urls = redirUrls
             * };
             * // Create a payment using a APIContext
             * return this.payment.Create(apiContext);
             */
        }
Esempio n. 29
0
 /// <summary>
 /// Partially update an existing web experience profile by passing the ID of the profile to the request URI. In addition, pass a patch object in the request JSON that specifies the operation to perform, path of the profile location to update, and a new value if needed to complete the operation.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="patchRequest">PatchRequest</param>
 public void PartialUpdate(APIContext apiContext, PatchRequest patchRequest)
 {
     WebProfile.PartialUpdate(apiContext, this.id, patchRequest);
 }
Esempio n. 30
0
 /// <summary>
 /// Create a web experience profile by passing the name of the profile and other profile details in the request JSON to the request URI.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <returns>CreateProfileResponse</returns>
 public CreateProfileResponse Create(APIContext apiContext)
 {
     return(WebProfile.Create(apiContext, this));
 }
Esempio n. 31
0
 /// <summary>
 /// Execute a billing agreement after buyer approval by passing the payment token to the request URI.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <returns>Agreement</returns>
 public Agreement Execute(APIContext apiContext)
 {
     return(Agreement.Execute(apiContext, this.token));
 }
Esempio n. 32
0
 /// <summary>
 /// Update a web experience profile by passing the ID of the profile to the request URI. In addition, pass the profile details in the request JSON. If your request does not include values for all profile detail fields, the previously set values for the omitted fields are removed by this operation.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 public void Update(APIContext apiContext)
 {
     WebProfile.Update(apiContext, this);
 }
Esempio n. 33
0
 /// <summary>
 /// Reactivate a suspended billing agreement by passing the ID of the agreement to the appropriate URI. In addition, pass an AgreementStateDescriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="agreementStateDescriptor">AgreementStateDescriptor</param>
 public void ReActivate(APIContext apiContext, AgreementStateDescriptor agreementStateDescriptor)
 {
     Agreement.ReActivate(apiContext, this.id, agreementStateDescriptor);
 }
Esempio n. 34
0
 /// <summary>
 /// Creates (and processes) a new Capture Transaction added as a related resource.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="capture">Capture</param>
 /// <returns>Capture</returns>
 public Capture Capture(APIContext apiContext, Capture capture)
 {
     return(Order.Capture(apiContext, this.id, capture));
 }
Esempio n. 35
0
 /// <summary>
 /// Reauthorizes an expired Authorization.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <returns>Authorization</returns>
 public Authorization Reauthorize(APIContext apiContext)
 {
     return(Authorization.Reauthorize(apiContext, this));
 }
Esempio n. 36
0
 /// <summary>
 /// Configures and executes REST call: Supports JSON
 /// </summary>
 /// <param name="apiContext">APIContext object</param>
 /// <param name="httpMethod">HttpMethod type</param>
 /// <param name="resource">URI path of the resource</param>
 /// <param name="payload">JSON request payload</param>
 /// <param name="endpoint">Optional endpoint to use when generating the full URL for the resource. If none is specified, a default endpoint is generated by the SDK based on other config settings.</param>
 /// <param name="setAuthorizationHeader">Specifies whether or not to set the Authorization header in outgoing requests. Defaults to true.</param>
 /// <returns>Response object or null otherwise for void API calls</returns>
 /// <exception cref="PayPal.HttpException">Thrown if there was an error sending the request.</exception>
 /// <exception cref="PayPal.PaymentsException">Thrown if an HttpException was raised and contains a Payments API error object.</exception>
 /// <exception cref="PayPal.PayPalException">Thrown for any other issues encountered. See inner exception for further details.</exception>
 protected internal static object ConfigureAndExecute(APIContext apiContext, HttpMethod httpMethod, string resource, string payload = "", string endpoint = "", bool setAuthorizationHeader = true)
 {
     return(ConfigureAndExecute <object>(apiContext, httpMethod, resource, payload, endpoint, setAuthorizationHeader));
 }
Esempio n. 37
0
 /// <summary>
 /// Update information in a previously saved bank account. Only the modified fields need to be passed in the request.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="patchRequest">PatchRequest</param>
 /// <returns>BankAccount</returns>
 public BankAccount Update(APIContext apiContext, PatchRequest patchRequest)
 {
     return(BankAccount.Update(apiContext, this.id, patchRequest));
 }
Esempio n. 38
0
 /// <summary>
 /// Creates the Webhook for the application associated with the access token.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <returns>Webhook</returns>
 public Webhook Create(APIContext apiContext)
 {
     return(Webhook.Create(apiContext, this));
 }
Esempio n. 39
0
 /// <summary>
 /// Deletes the Webhook identified by webhook_id for the application associated with access token.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 public void Delete(APIContext apiContext)
 {
     Webhook.Delete(apiContext, this.id);
 }
Esempio n. 40
0
 /// <summary>
 /// Updates the Webhook identified by webhook_id for the application associated with access token.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="patchRequest">PatchRequest</param>
 /// <returns>Webhook</returns>
 public Webhook Update(APIContext apiContext, PatchRequest patchRequest)
 {
     return(Webhook.Update(apiContext, this.id, patchRequest));
 }
Esempio n. 41
0
 /// <summary>
 /// Creates a new Bank Account Resource.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <returns>BankAccount</returns>
 public BankAccount Create(APIContext apiContext)
 {
     return(BankAccount.Create(apiContext, this));
 }
Esempio n. 42
0
 /// <summary>
 /// Delete the bank account resource for the given identifier.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 public void Delete(APIContext apiContext)
 {
     BankAccount.Delete(apiContext, this.id);
 }
Esempio n. 43
0
 /// <summary>
 /// Suspend a particular billing agreement by passing the ID of the agreement to the request URI.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="agreementStateDescriptor">AgreementStateDescriptor</param>
 public void Suspend(APIContext apiContext, AgreementStateDescriptor agreementStateDescriptor)
 {
     Agreement.Suspend(apiContext, this.id, agreementStateDescriptor);
 }
Esempio n. 44
0
 /// <summary>
 /// Captures a payment for an order, by ID. To use this call, the original payment call must specify an intent of `order`. In the JSON request body, include the payment amount and indicate whether this capture is the final capture for the authorization.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="capture">Capture</param>
 /// <returns>Capture</returns>
 public Capture Capture(APIContext apiContext, Capture capture)
 {
     return Order.Capture(apiContext, this.id, capture);
 }
Esempio n. 45
0
 /// <summary>
 /// Update details of a billing agreement, such as the description, shipping address, and start date, by passing the ID of the agreement to the request URI.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="patchRequest">PatchRequest</param>
 public void Update(APIContext apiContext, PatchRequest patchRequest)
 {
     Agreement.Update(apiContext, this.id, patchRequest);
 }
Esempio n. 46
0
        private Payment CreatePayment(APIContext apiContext, string redirectUrl)
        {
            //similar to credit card create itemlist and add item objects to it
            var itemList = new ItemList() { items = new List<Item>() };

            itemList.items.Add(new Item()
            {
                name = "Item Name",
                currency = "EUR",
                price = "150",
                quantity = "1",
                sku = "sku"
            });

            var payer = new Payer() { payment_method = "paypal" };

            // Configure Redirect Urls here with RedirectUrls object
            var redirUrls = new RedirectUrls()
            {
                cancel_url = redirectUrl,
                return_url = redirectUrl
            };

            // similar as we did for credit card, do here and create details object
            var details = new Details()
            {
                tax = "27",
                shipping = "1",
                subtotal = "150"
            };

            // similar as we did for credit card, do here and create amount object
            var amount = new Amount()
            {
                currency = "EUR",
                total = "178", // Total must be equal to sum of shipping, tax and subtotal.
                details = details
            };

            var transactionList = new List<Transaction>();

            transactionList.Add(new Transaction()
            {
                description = "Transaction description.",
                invoice_number = "your invoice number",
                amount = amount,
                item_list = itemList
            });

            this.payment = new Payment()
            {
                intent = "sale",
                payer = payer,
                transactions = transactionList,
                redirect_urls = redirUrls
            };

            // Create a payment using a APIContext
            return this.payment.Create(apiContext);
        }
Esempio n. 47
0
 /// <summary>
 /// Create a new billing agreement by passing the details for the agreement, including the name, description, start date, payer, and billing plan in the request JSON.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <returns>Agreement</returns>
 public Agreement Create(APIContext apiContext)
 {
     return(Agreement.Create(apiContext, this));
 }
Esempio n. 48
0
 /// <summary>
 /// Creates an authorization on an order
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <returns>Authorization</returns>
 public Authorization Authorize(APIContext apiContext)
 {
     return(Order.Authorize(apiContext, this));
 }
Esempio n. 49
0
 /// <summary>
 /// Delete an existing web experience profile by passing the profile ID to the request URI.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 public void Delete(APIContext apiContext)
 {
     WebProfile.Delete(apiContext, this.id);
 }
Esempio n. 50
0
 /// <summary>
 /// Set the balance for an agreement by passing the ID of the agreement to the request URI. In addition, pass a Currency object in the request JSON that specifies the currency type and value of the balance.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="currency">Currency</param>
 public void SetBalance(APIContext apiContext, Currency currency)
 {
     Agreement.SetBalance(apiContext, this.id, currency);
 }
Esempio n. 51
0
 /// <summary>
 /// Create a payout batch resource by passing a sender_batch_header and an items array to the request URI. The sender_batch_header contains payout parameters that describe the handling of a batch resource while the items array conatins payout items.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="syncMode">A value of true will provide an immediate, synchronous response. Without this query keyword or if the value is false, the response will be a background batch mode.</param>
 /// <returns>PayoutCreateResponse</returns>
 public PayoutBatch Create(APIContext apiContext, bool syncMode = false)
 {
     return(Payout.Create(apiContext, this, syncMode));
 }
Esempio n. 52
0
 /// <summary>
 /// Bill an outstanding amount for an agreement by passing the ID of the agreement to the request URI. In addition, pass an AgreementStateDescriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="agreementStateDescriptor">AgreementStateDescriptor</param>
 public void BillBalance(APIContext apiContext, AgreementStateDescriptor agreementStateDescriptor)
 {
     Agreement.BillBalance(apiContext, this.id, agreementStateDescriptor);
 }
Esempio n. 53
0
 /// <summary>
 /// Cancel a billing agreement by passing the ID of the agreement to the request URI. In addition, pass an agreement_state_descriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="agreementStateDescriptor">AgreementStateDescriptor</param>
 public void Cancel(APIContext apiContext, AgreementStateDescriptor agreementStateDescriptor)
 {
     Agreement.Cancel(apiContext, this.id, agreementStateDescriptor);
 }
Esempio n. 54
0
 /// <summary>
 /// Creates a new Credit Card Resource (aka Tokenize).
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <returns>CreditCard</returns>
 public CreditCard Create(APIContext apiContext)
 {
     return(CreditCard.Create(apiContext, this));
 }
Esempio n. 55
0
 /// <summary>
 /// Voids, or cancels, an order, by ID. You cannot void an order if a payment has already been partially or fully captured.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <returns>Order</returns>
 public Order Void(APIContext apiContext)
 {
     return Order.Void(apiContext, this.id);
 }
Esempio n. 56
0
        public String SubmitRechargeInfo(String paymentId, String amount, String paymentTime)
        {
            OAuthTokenCredential oa = new OAuthTokenCredential("AQmW6s0chChHeblhmaIYQda6Bn1gmfSSUnvUCHNCLZM_7BiLOb5BMrINuIxUswdG8Prb8K3ktHQpZuho", "ENQKqkutUnKuTGBWiNDvJ_sA131lwCU4c1eaJwFcn58M88LtjHJd9TLgvjT4nuXkruuSkD0OF0u_XP_W");


            PayPal.Api.APIContext apiContext = new PayPal.Api.APIContext(oa.GetAccessToken());

            try
            {
                Payment payment = PayPal.Api.Payment.Get(apiContext, paymentId);

                if (payment == null || String.IsNullOrEmpty(payment.id))
                {
                    return("11");
                }
            }
            catch (Exception ex)
            {
                return("11");
            }

            LoginViewModel user = Utils.GetUserInfo();

            PaymentInfo pInfo = null;

            using (DSLEntities entity = new DSLEntities())
            {
                pInfo = entity.PaymentInfo.Where(a => a.UserId.ToString() == user.UserId && a.PaymentId == paymentId).ToList().FirstOrDefault();
            }

            if (pInfo != null)
            {
                return("1");
            }



            UserInfo existingData = null;


            using (DSLEntities entity = new DSLEntities())
            {
                existingData = entity.UserInfo.Where(a => a.UserId.ToString() == user.UserId).ToList().FirstOrDefault();
            }

            if (existingData != null)
            {
                using (DSLEntities entity = new DSLEntities())
                {
                    existingData.Balance            += decimal.Parse(amount);
                    entity.Entry(existingData).State = System.Data.Entity.EntityState.Modified;
                    entity.SaveChanges();
                }
            }

            PaymentInfo addPayInfo = new PaymentInfo();

            addPayInfo.Amount       = Decimal.Parse(amount);
            addPayInfo.PaymentId    = paymentId;
            addPayInfo.PaymentState = "Approval";
            addPayInfo.PaymentType  = "PayPal";
            addPayInfo.UserId       = int.Parse(user.UserId);
            addPayInfo.PaymentTime  = DateTime.Parse(paymentTime);



            using (DSLEntities entity = new DSLEntities())
            {
                entity.PaymentInfo.Add(addPayInfo);
                entity.SaveChanges();
            }


            return("0");
        }
Esempio n. 57
0
 /// <summary>
 /// Creates (and processes) a new Capture Transaction added as a related resource.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="capture">Capture</param>
 /// <returns>Capture</returns>
 public Capture Capture(APIContext apiContext, Capture capture)
 {
     return(Authorization.Capture(apiContext, this.id, capture));
 }
Esempio n. 58
0
 /// <summary>
 /// Voids (cancels) an Order.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <returns>Order</returns>
 public Order Void(APIContext apiContext)
 {
     return(Order.Void(apiContext, this.id));
 }
 private Payment ExecutePayment(APIContext apiContext, string payerId, string paymentId)
 {
     var paymentExecution = new PaymentExecution() { payer_id = payerId };
     payment = new Payment() { id = paymentId };
     return payment.Execute(apiContext, paymentExecution);
 }
Esempio n. 60
0
 /// <summary>
 /// Voids (cancels) an Authorization.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <returns>Authorization</returns>
 public Authorization Void(APIContext apiContext)
 {
     return(Authorization.Void(apiContext, this.id));
 }