Пример #1
0
        /// <summary>
        /// Full update of the invoice resource for the given identifier.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="invoice">Invoice object to update.</param>
        /// <param name="notifyMerchant">Specifies if the invoice update notification is needed for merchant</param>
        /// <returns>Invoice</returns>
        public static Invoice Update(APIContext apiContext, Invoice invoice, bool notifyMerchant = true)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(invoice, "invoice");

            var queryParameters = new QueryParameters();

            queryParameters["notify_merchant"] = notifyMerchant.ToString();

            // Configure and send the request
            var pattern      = "v1/invoicing/invoices/{0}";
            var resourcePath = SDKUtil.FormatURIPath(pattern, new object[] { invoice.id }) + queryParameters.ToUrlFormattedString();

            return(PayPalResource.ConfigureAndExecute <Invoice>(apiContext, HttpMethod.PUT, resourcePath, invoice.ConvertToJson()));
        }
Пример #2
0
        /// <summary>
        /// Retrieves the list of Webhooks events resources for the application associated with token. The developers can use it to see list of past webhooks events.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="pageSize">Number of items to be returned by a GET operation</param>
        /// <param name="startTime">Resource creation time that indicates the start of a range of results.</param>
        /// <param name="endTime">Resource creation time that indicates the end of a range of results.</param>
        /// <returns>WebhookEventList</returns>
        public static WebhookEventList List(APIContext apiContext, int pageSize = 10, string startTime = "", string endTime = "")
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);

            var queryParameters = new QueryParameters();

            queryParameters["page_size"]  = pageSize.ToString();
            queryParameters["start_time"] = startTime;
            queryParameters["end_time"]   = endTime;

            // Configure and send the request
            var resourcePath = "v1/notifications/webhooks-events" + queryParameters.ToUrlFormattedString();

            return(PayPalResource.ConfigureAndExecute <WebhookEventList>(apiContext, HttpMethod.GET, resourcePath));
        }
Пример #3
0
        /// <summary>
        /// Get all invoices of a merchant.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="page">Start index.</param>
        /// <param name="pageSize">Number of invoices to be returned by the GET API.</param>
        /// <param name="totalCountRequired">A flag to depict that total_count should be returned in the response.</param>
        /// <returns>InvoiceSearchResponse</returns>
        public static InvoiceSearchResponse GetAll(APIContext apiContext, int page = 1, int pageSize = 20, bool totalCountRequired = false)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);

            var queryParameters = new QueryParameters();

            queryParameters["page"]                 = page.ToString();
            queryParameters["page_size"]            = pageSize.ToString();
            queryParameters["total_count_required"] = totalCountRequired.ToString();

            // Configure and send the request
            var resourcePath = "v1/invoicing/invoices" + queryParameters.ToUrlFormattedString();

            return(PayPalResource.ConfigureAndExecute <InvoiceSearchResponse>(apiContext, HttpMethod.GET, resourcePath));
        }
Пример #4
0
        /// <summary>
        /// Sends a legitimate invoice to the payer.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="invoiceId">ID of the invoice to send.</param>
        /// <param name="notifyMerchant">Specifies if the invoice send notification is needed for merchant</param>
        public static void Send(APIContext apiContext, string invoiceId, bool notifyMerchant = true)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(invoiceId, "invoiceId");

            var queryParameters = new QueryParameters();

            queryParameters["notify_merchant"] = notifyMerchant.ToString();

            // Configure and send the request
            var pattern      = "v1/invoicing/invoices/{0}/send";
            var resourcePath = SDKUtil.FormatURIPath(pattern, new object[] { invoiceId }) + queryParameters.ToUrlFormattedString();

            PayPalResource.ConfigureAndExecute(apiContext, HttpMethod.POST, resourcePath);
        }
Пример #5
0
        /// <summary>
        /// Helper method for creating Access and Refresh Tokens from an Authorization Code.
        /// </summary>
        /// <param name="apiContext">APIContext to be used for the call.</param>
        /// <param name="createFromAuthorizationCodeParameters">Query parameters used for the API call.</param>
        /// <param name="resourcePath">The path to the REST API resource that will be requested.</param>
        /// <returns>A TokenInfo object containing the Access and Refresh Tokens.</returns>
        private static Tokeninfo CreateFromAuthorizationCodeParameters(APIContext apiContext, CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters, string resourcePath)
        {
            var payLoad = resourcePath.Substring(resourcePath.IndexOf('?') + 1);

            resourcePath = resourcePath.Substring(0, resourcePath.IndexOf("?"));
            var headersMap = new Dictionary <string, string>();

            headersMap.Add(BaseConstants.ContentTypeHeader, "application/x-www-form-urlencoded");
            if (apiContext == null)
            {
                apiContext = new APIContext();
            }
            apiContext.HTTPHeaders   = headersMap;
            apiContext.MaskRequestId = true;
            return(PayPalResource.ConfigureAndExecute <Tokeninfo>(apiContext, HttpMethod.POST, resourcePath, payLoad));
        }
Пример #6
0
        /// <summary>
        /// List billing plans according to optional query string parameters specified.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="page">A non-zero integer representing the 'page' of the results.</param>
        /// <param name="status">Specifies the status (CREATED, ACTIVE, or INACTIVE) of the billing plans to return.</param>
        /// <param name="pageSize">A non-negative, non-zero integer indicating the maximum number of results to return at one time.</param>
        /// <param name="totalRequired">A boolean indicating total number of items (total_items) and pages (total_pages) are expected to be returned in the response</param>
        /// <returns>PlanList</returns>
        public static PlanList List(APIContext apiContext, string page = "0", string status = "CREATED", string pageSize = "10", string totalRequired = "yes")
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);

            var queryParameters = new QueryParameters();

            queryParameters["page"]           = page;
            queryParameters["status"]         = status;
            queryParameters["page_size"]      = pageSize;
            queryParameters["total_required"] = totalRequired;

            // Configure and send the request
            var resourcePath = "v1/payments/billing-plans" + queryParameters.ToUrlFormattedString();

            return(PayPalResource.ConfigureAndExecute <PlanList>(apiContext, HttpMethod.GET, resourcePath));
        }
Пример #7
0
        /// <summary>
        /// List transactions for a billing agreement by passing the ID of the agreement, as well as the start and end dates of the range of transactions to list, to the request URI.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="agreementId">Identifier of the agreement resource for which to list transactions.</param>
        /// <param name="startDate">The start date of the range of transactions to list.</param>
        /// <param name="endDate">The end date of the range of transactions to list.</param>
        /// <returns>AgreementTransactions</returns>
        public static AgreementTransactions ListTransactions(APIContext apiContext, string agreementId, string startDate = "", string endDate = "")
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(agreementId, "agreementId");

            var queryParameters = new QueryParameters();

            queryParameters["start_date"] = startDate;
            queryParameters["end_date"]   = endDate;

            // Configure and send the request
            var pattern      = "v1/payments/billing-agreements/{0}/transactions";
            var resourcePath = SDKUtil.FormatURIPath(pattern, new object[] { agreementId }) + queryParameters.ToUrlFormattedString();

            return(PayPalResource.ConfigureAndExecute <AgreementTransactions>(apiContext, HttpMethod.GET, resourcePath));
        }
Пример #8
0
        /// <summary>
        /// Generates a QR code for an invoice, by ID.<br/><br/>The QR code is a PNG image in [Base64-encoded](https://www.base64encode.org/) format that corresponds to the invoice ID. You can generate a QR code for an invoice and add it to a paper or PDF invoice. When a customer uses their mobile device to scan the QR code, he or she is redirected to the PayPal mobile payment flow where he or she can pay online with PayPal or a credit card.<br/><br/>Before you get a QR code, you must:<ol><li><p>[Create an invoice](#invoices_create). Specify `[email protected]` as the recipient email address in the `billing_info` object. Use a customer email address only if you want to email the invoice.</p></li><li><p>[Send an invoice](#invoices_send) to move the invoice from a draft to payable state. If you specify `[email protected]` as the recipient email address, the invoice is not emailed.</p></li></ol>
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="invoiceId">The ID of the invoice for which to generate a QR code.</param>
        /// <param name="width">The width, in pixels, of the QR code image. Valid value is from 150 to 500. Default is 500.</param>
        /// <param name="height">The height, in pixels, of the QR code image. Valid value is from 150 to 500. Default is 500.</param>
        /// <param name="action">The type of URL for which to generate a QR code. Default is `pay` and is the only supported value.</param>
        /// <returns>Image</returns>
        public static Image QrCode(APIContext apiContext, string invoiceId, int width = 500, int height = 500, string action = "pay")
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(invoiceId, "invoiceId");

            var queryParameters = new QueryParameters();

            queryParameters["width"]  = width.ToString();
            queryParameters["height"] = height.ToString();
            queryParameters["action"] = action;

            // Configure and send the request
            var pattern      = "v1/invoicing/invoices/{0}/qr-code";
            var resourcePath = SDKUtil.FormatURIPath(pattern, new object[] { invoiceId }) + queryParameters.ToUrlFormattedString();

            return(PayPalResource.ConfigureAndExecute <Image>(apiContext, HttpMethod.GET, resourcePath));
        }
        /// <summary>
        /// Lists all webhooks for an app.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="anchorType">Filters the response by an entity type, `anchor_id`. Value is `APPLICATION` or `ACCOUNT`. Default is `APPLICATION`.</param>
        /// <returns>WebhookList</returns>
        public static WebhookList GetAll(APIContext apiContext, string anchorType = null)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            var queryParameters = new QueryParameters();

            if (anchorType != null)
            {
                ArgumentValidator.Validate(anchorType, "anchorType");
                queryParameters["anchor_type"] = anchorType;
            }


            // Configure and send the request
            var resourcePath = "v1/notifications/webhooks" + queryParameters.ToUrlFormattedString();

            return(PayPalResource.ConfigureAndExecute <WebhookList>(apiContext, HttpMethod.GET, resourcePath));
        }
Пример #10
0
        /// <summary>
        /// Creates an Access Token from an Refresh Token
        /// <param name="apiContext">APIContext to be used for the call</param>
        /// <param name="createFromRefreshTokenParameters">Query parameters used for API call</param>
        /// </summary>
        public Tokeninfo CreateFromRefreshToken(APIContext apiContext, CreateFromRefreshTokenParameters createFromRefreshTokenParameters)
        {
            string pattern = "v1/identity/openidconnect/tokenservice?grant_type={0}&refresh_token={1}&scope={2}&client_id={3}&client_secret={4}";

            createFromRefreshTokenParameters.SetRefreshToken(HttpUtility.UrlEncode(refresh_token));
            object[] parameters   = new object[] { createFromRefreshTokenParameters };
            string   resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string   payLoad      = resourcePath.Substring(resourcePath.IndexOf('?') + 1);

            resourcePath = resourcePath.Substring(0, resourcePath.IndexOf("?"));
            Dictionary <string, string> headersMap = new Dictionary <string, string>();

            headersMap.Add(BaseConstants.ContentTypeHeader, "application/x-www-form-urlencoded");
            if (apiContext == null)
            {
                apiContext = new APIContext();
            }
            apiContext.HTTPHeaders   = headersMap;
            apiContext.MaskRequestId = true;
            return(PayPalResource.ConfigureAndExecute <Tokeninfo>(apiContext, HttpMethod.POST, resourcePath, payLoad));
        }
Пример #11
0
        /// <summary>
        /// Retrieves a list of Credit Card resources.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="pageSize">Number of items to be returned in the current page size, by a GET operation.</param>
        /// <param name="page">The page number to be retrieved, for the list of items, by the current GET request.</param>
        /// <param name="startTime">Resource creation time  as ISO8601 date-time format (ex: 1994-11-05T13:15:30Z) that indicates the start of a range of results.</param>
        /// <param name="endTime">Resource creation time as ISO8601 date-time format (ex: 1994-11-05T13:15:30Z) that indicates the end of a range of results.</param>
        /// <param name="sortOrder">Sort based on order of results. Options include 'asc' for ascending order or 'desc' for descending order.</param>
        /// <param name="sortBy">Sort based on 'create_time' or 'update_time'.</param>
        /// <param name="merchantId">Merchant identifier to filter the search results in list operations.</param>
        /// <param name="externalCardId">Externally provided card identifier to filter the search results in list operations.</param>
        /// <param name="externalCustomerId">Externally provided customer identifier to filter the search results in list operations.</param>
        /// <returns>CreditCardList</returns>
        public static CreditCardList List(APIContext apiContext, int pageSize = 10, int page = 1, string startTime = "", string endTime = "", string sortOrder = "asc", string sortBy = "create_time", string merchantId = "", string externalCardId = "", string externalCustomerId = "")
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);

            var queryParameters = new QueryParameters();

            queryParameters["page_size"]            = pageSize.ToString();
            queryParameters["page"]                 = page.ToString();
            queryParameters["start_time"]           = startTime;
            queryParameters["end_time"]             = endTime;
            queryParameters["sort_order"]           = sortOrder;
            queryParameters["sort_by"]              = sortBy;
            queryParameters["merchant_id"]          = merchantId;
            queryParameters["external_card_id"]     = externalCardId;
            queryParameters["external_customer_id"] = externalCustomerId;

            // Configure and send the request
            var resourcePath = "v1/vault/credit-cards" + queryParameters.ToUrlFormattedString();

            return(PayPalResource.ConfigureAndExecute <CreditCardList>(apiContext, HttpMethod.GET, resourcePath));
        }
Пример #12
0
        /// <summary>
        /// Retrieves a list of payments.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="count">Number of items to be returned by a GET operation.</param>
        /// <param name="startId">A resource ID that indicates the starting resource in the returned results.</param>
        /// <param name="startIndex">Start index of the resources to be returned. Typically used to jump to a specific position in the resource history based on it's cart.</param>
        /// <param name="startTime">Resource creation time in ISO-8601 format that indicates the start of a range of results. Example: start_time=2016-03-06T11:00:00Z.</param>
        /// <param name="endTime">Resource creation time in ISO-8601 format that indicates the end of a range of results. Example: end_time=2016-03-20T10:30:00Z.</param>
        /// <param name="startDate">Resource creation date that indicates the start of results.</param>
        /// <param name="endDate">Resource creation date that indicates the end of a range of results.</param>
        /// <param name="payeeEmail">Payee identifier (email) to filter the search results in list operations.</param>
        /// <param name="payeeId">Payee identifier (merchant id) assigned by PayPal to filter the search results in list operations.</param>
        /// <param name="sortBy">Field name that determines sort order of results.</param>
        /// <param name="sortOrder">Specifies if order of results is ascending or descending.</param>
        /// <returns>PaymentHistory</returns>
        public static PaymentHistory List(APIContext apiContext, int?count = null, string startId = "", int?startIndex = null, string startTime = "", string endTime = "", string startDate = "", string endDate = "", string payeeEmail = "", string payeeId = "", string sortBy = "", string sortOrder = "")
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);

            var queryParameters = new QueryParameters();

            queryParameters["count"]       = count.ToString();
            queryParameters["start_id"]    = startId;
            queryParameters["start_index"] = startIndex.ToString();
            queryParameters["start_time"]  = startTime;
            queryParameters["end_time"]    = endTime;
            queryParameters["start_date"]  = startDate;
            queryParameters["end_date"]    = endDate;
            queryParameters["payee_email"] = payeeEmail;
            queryParameters["payee_id"]    = payeeId;
            queryParameters["sort_by"]     = sortBy;
            queryParameters["sort_order"]  = sortOrder;

            // Configure and send the request
            var resourcePath = "v1/payments/payment" + queryParameters.ToUrlFormattedString();

            return(PayPalResource.ConfigureAndExecute <PaymentHistory>(apiContext, HttpMethod.GET, resourcePath));
        }