/// <summary>
        /// Delete the Credit Card resource for the given identifier.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <returns></returns>
        public void Delete(APIContext apiContext)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(this.id, "Id");

            // Configure and send the request
            apiContext.MaskRequestId = true;
            object[] parameters   = new object[] { this.id };
            string   pattern      = "v1/vault/credit-card/{0}";
            string   resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string   payLoad      = "";

            PayPalResource.ConfigureAndExecute <object>(apiContext, HttpMethod.DELETE, resourcePath, payLoad);
            return;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Mark the status of the invoice as refunded.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="refundDetail">RefundDetail</param>
        /// <returns></returns>
        public void RecordRefund(APIContext apiContext, RefundDetail refundDetail)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(this.id, "Id");
            ArgumentValidator.Validate(refundDetail, "refundDetail");

            // Configure and send the request
            object[] parameters   = new object[] { this.id };
            string   pattern      = "v1/invoicing/invoices/{0}/record-refund";
            string   resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string   payLoad      = refundDetail.ConvertToJson();

            PayPalResource.ConfigureAndExecute <object>(apiContext, HttpMethod.POST, resourcePath, payLoad);
            return;
        }
Ejemplo n.º 3
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"></param>
        /// <returns></returns>
        public void PartialUpdate(APIContext apiContext, PatchRequest patchRequest)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(this.id, "Id");
            ArgumentValidator.Validate(patchRequest, "patchRequest");

            // Configure and send the request
            object[] parameters   = new object[] { this.id };
            string   pattern      = "v1/payment-experience/web-profiles/{0}";
            string   resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string   payLoad      = patchRequest.ConvertToJson();

            PayPalResource.ConfigureAndExecute <object>(apiContext, HttpMethod.PATCH, resourcePath, payLoad);
            return;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Cancels an invoice.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="cancelNotification">CancelNotification</param>
        /// <returns></returns>
        public void Cancel(APIContext apiContext, CancelNotification cancelNotification)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(this.id, "Id");
            ArgumentValidator.Validate(cancelNotification, "cancelNotification");

            // Configure and send the request
            object[] parameters   = new object[] { this.id };
            string   pattern      = "v1/invoicing/invoices/{0}/cancel";
            string   resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string   payLoad      = cancelNotification.ConvertToJson();

            PayPalResource.ConfigureAndExecute <object>(apiContext, HttpMethod.POST, resourcePath, payLoad);
            return;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Voids (cancels) an Authorization.
        /// </summary>
        public Authorization Void(APIContext apiContext)
        {
            if (string.IsNullOrEmpty(apiContext.AccessToken))
            {
                throw new ArgumentNullException("AccessToken cannot be null or empty");
            }
            if (this.id == null)
            {
                throw new ArgumentNullException("Id cannot be null");
            }
            object[] parameters   = new object[] { this.id };
            string   pattern      = "v1/payments/authorization/{0}/void";
            string   resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string   payLoad      = "";

            return(PayPalResource.ConfigureAndExecute <Authorization>(apiContext, HttpMethod.POST, resourcePath, payLoad));
        }
Ejemplo n.º 6
0
        public static PaymentHistory Get(APIContext apiContext, QueryParameters queryParameters)
        {
            if (string.IsNullOrEmpty(apiContext.AccessToken))
            {
                throw new ArgumentNullException("AccessToken cannot be null or empty");
            }
            if (queryParameters == null)
            {
                throw new ArgumentNullException("queryParameters cannot be null");
            }
            object[] parameters   = new object[] { queryParameters };
            string   pattern      = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}";
            string   resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string   payLoad      = "";

            return(PayPalResource.ConfigureAndExecute <PaymentHistory>(apiContext, HttpMethod.GET, resourcePath, payLoad));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Obtain the Credit Card resource for the given identifier.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="creditCardId">string</param>
        /// <returns>CreditCard</returns>
        public static CreditCard Get(APIContext apiContext, string creditCardId)
        {
            if (string.IsNullOrEmpty(apiContext.AccessToken))
            {
                throw new ArgumentNullException("AccessToken cannot be null or empty");
            }
            if (creditCardId == null)
            {
                throw new ArgumentNullException("creditCardId cannot be null");
            }
            object[] parameters   = new object[] { creditCardId };
            string   pattern      = "v1/vault/credit-card/{0}";
            string   resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string   payLoad      = "";

            return(PayPalResource.ConfigureAndExecute <CreditCard>(apiContext, HttpMethod.GET, resourcePath, payLoad));
        }
Ejemplo n.º 8
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">string</param>
        /// <returns>AgreementTransactions</returns>
        public static AgreementTransactions ListTransactions(APIContext apiContext, string agreementId, DateTime startDate, DateTime endDate)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(agreementId, "agreementId");
            ArgumentValidator.Validate(startDate, "startDate");
            ArgumentValidator.Validate(endDate, "endDate");

            // Configure and send the request
            var dateFormat = "yyyy-MM-dd";

            object[] parameters   = new object[] { agreementId, startDate.ToString(dateFormat), endDate.ToString(dateFormat) };
            string   pattern      = "v1/payments/billing-agreements/{0}/transactions?start_date={1}&end_date={2}";
            string   resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string   payLoad      = "";

            return(PayPalResource.ConfigureAndExecute <AgreementTransactions>(apiContext, HttpMethod.GET, resourcePath, payLoad));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Get call for Refund.
        /// GET /v1/payments/refund/:refundId
        /// <param name="apiContext">APIContext required for the call</param>
        /// <param name="refundId">RefundId</param>
        /// <returns>Returns Refund object</returns>
        /// </summary>
        public static Refund Get(APIContext apiContext, string refundId)
        {
            if (string.IsNullOrEmpty(apiContext.AccessToken))
            {
                throw new ArgumentNullException("AccessToken cannot be null");
            }
            if (String.IsNullOrEmpty(refundId))
            {
                throw new System.ArgumentNullException("refundId cannot be null or empty");
            }
            string pattern = "v1/payments/refund/{0}";

            object[] container    = new Object[] { refundId };
            string   resourcePath = SDKUtil.FormatURIPath(pattern, container);
            string   payLoad      = string.Empty;

            return(PayPalResource.ConfigureAndExecute <Refund>(apiContext, HttpMethod.GET, resourcePath, payLoad));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Delete the Credit Card resource for the given identifier. Returns 204 No Content when the card is deleted successfully.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <returns></returns>
        public void Delete(APIContext apiContext)
        {
            if (string.IsNullOrEmpty(apiContext.AccessToken))
            {
                throw new ArgumentNullException("AccessToken cannot be null or empty");
            }
            if (this.id == null)
            {
                throw new ArgumentNullException("Id cannot be null");
            }
            apiContext.MaskRequestId = true;
            object[] parameters   = new object[] { this.id };
            string   pattern      = "v1/vault/credit-card/{0}";
            string   resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string   payLoad      = "";

            PayPalResource.ConfigureAndExecute <object>(apiContext, HttpMethod.DELETE, resourcePath, payLoad);
            return;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates an Access Token from an Authorization Code.
        /// <param name="apiContext">APIContext to be used for the call.</param>
        /// <param name="createFromAuthorizationCodeParameters">Query parameters used for API call</param>
        /// </summary>
        public static Tokeninfo CreateFromAuthorizationCode(APIContext apiContext, CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters)
        {
            string pattern = "v1/identity/openidconnect/tokenservice?grant_type={0}&code={1}&redirect_uri={2}";

            object[] parameters   = new object[] { createFromAuthorizationCodeParameters };
            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>();

            if (createFromAuthorizationCodeParameters.getClientId() != null && createFromAuthorizationCodeParameters.getClientSecret() != null)
            {
                OAuthTokenCredential oauthTokenCredential = new OAuthTokenCredential(createFromAuthorizationCodeParameters.getClientId(), createFromAuthorizationCodeParameters.getClientSecret());
                headersMap.Add("Authorization", oauthTokenCredential.GenerateBasicAuthHeader());
            }
            headersMap.Add("Content-Type", "application/x-www-form-urlencoded");
            return(PayPalResource.ConfigureAndExecute <Tokeninfo>(apiContext, HttpMethod.POST,
                                                                  resourcePath, headersMap, payLoad));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates an Access Token from an Authorization Code.
        /// <param name="apiContext">APIContext to be used for the call.</param>
        /// <param name="createFromAuthorizationCodeParameters">Query parameters used for API call</param>
        /// </summary>
        public static Tokeninfo CreateFromAuthorizationCode(APIContext apiContext, CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters)
        {
            string pattern = "v1/identity/openidconnect/tokenservice?grant_type={0}&code={1}&redirect_uri={2}";

            object[] parameters   = new object[] { createFromAuthorizationCodeParameters };
            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));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates (and processes) a new Payment Resource.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <returns>Payment</returns>
        public Payment Create(APIContext apiContext)
        {
            if (apiContext == null)
            {
                throw new ArgumentNullException("APIContext cannot be null");
            }
            if (string.IsNullOrEmpty(apiContext.AccessToken))
            {
                throw new ArgumentNullException("AccessToken cannot be null or empty");
            }
            if (apiContext.HTTPHeaders == null)
            {
                apiContext.HTTPHeaders = new Dictionary <string, string>();
            }
            apiContext.HTTPHeaders.Add(BaseConstants.ContentTypeHeader, BaseConstants.ContentTypeHeaderJson);
            apiContext.SdkVersion = new SDKVersionImpl();
            string resourcePath = "v1/payments/payment";
            string payLoad      = this.ConvertToJson();

            return(PayPalResource.ConfigureAndExecute <Payment>(apiContext, HttpMethod.POST, resourcePath, payLoad));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates (and processes) a new Refund Transaction added as a related resource.
        /// </summary>
        public Refund Refund(APIContext apiContext, Refund refund)
        {
            if (string.IsNullOrEmpty(apiContext.AccessToken))
            {
                throw new ArgumentNullException("AccessToken cannot be null or empty");
            }
            if (this.id == null)
            {
                throw new ArgumentNullException("Id cannot be null");
            }
            if (refund == null)
            {
                throw new ArgumentNullException("refund cannot be null");
            }
            object[] parameters   = new object[] { this.id };
            string   pattern      = "v1/payments/capture/{0}/refund";
            string   resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string   payLoad      = refund.ConvertToJson();

            return(PayPalResource.ConfigureAndExecute <Refund>(apiContext, HttpMethod.POST, resourcePath, payLoad));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Executes the payment (after approved by the Payer) associated with this resource when the payment method is PayPal.
        /// </summary>
        public Payment Execute(APIContext apiContext, PaymentExecution paymentExecution)
        {
            if (string.IsNullOrEmpty(apiContext.AccessToken))
            {
                throw new ArgumentNullException("AccessToken cannot be null or empty");
            }
            if (this.id == null)
            {
                throw new ArgumentNullException("Id cannot be null");
            }
            if (paymentExecution == null)
            {
                throw new ArgumentNullException("paymentExecution cannot be null");
            }
            object[] parameters   = new object[] { this.id };
            string   pattern      = "v1/payments/payment/{0}/execute";
            string   resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string   payLoad      = paymentExecution.ConvertToJson();

            return(PayPalResource.ConfigureAndExecute <Payment>(apiContext, HttpMethod.POST, resourcePath, payLoad));
        }
Ejemplo n.º 16
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)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);

            // Configure and send the request
            string resourcePath = "v1/payments/billing-agreements";
            string payLoad      = this.ConvertToJson();
            var    agreement    = PayPalResource.ConfigureAndExecute <Agreement>(apiContext, HttpMethod.POST, resourcePath, payLoad);

            // Store the token referenced in the approval_url of the returned object.
            foreach (var links in agreement.links)
            {
                if (links.rel.Equals("approval_url"))
                {
                    var url = new Uri(links.href);
                    agreement.token = HttpUtility.ParseQueryString(url.Query).Get("token");
                    break;
                }
            }
            return(agreement);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Get all invoices of a merchant.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <returns>Invoices</returns>
        public static Invoices GetAll(APIContext apiContext)
        {
            if (apiContext == null)
            {
                throw new ArgumentNullException("APIContext cannot be null");
            }
            if (string.IsNullOrEmpty(apiContext.AccessToken))
            {
                throw new ArgumentNullException("AccessToken cannot be null or empty");
            }
            if (apiContext.HTTPHeaders == null)
            {
                apiContext.HTTPHeaders = new Dictionary <string, string>();
            }
            apiContext.HTTPHeaders.Add(BaseConstants.ContentTypeHeader, BaseConstants.ContentTypeHeaderJson);
            apiContext.SdkVersion = new SDKVersionImpl();
            string pattern      = "v1/invoicing/invoices";
            string resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string payLoad      = "";

            return(PayPalResource.ConfigureAndExecute <Invoices>(apiContext, HttpMethod.GET, resourcePath, payLoad));
        }
Ejemplo n.º 18
0
        public WebhookEvent SimulateEvent(string eventType, string webhookId)
        {
            var apiContext = GetApiContext();

            if (apiContext.HTTPHeaders == null)
            {
                apiContext.HTTPHeaders = new Dictionary <string, string>();
            }
            apiContext.HTTPHeaders["Content-Type"] = "application/json";
            apiContext.SdkVersion = new SDKVersion();

            string resource = "v1/notifications/simulate-event";

            var data = new
            {
                webhook_id = webhookId,
                event_type = eventType
            };

            var webhookEvent = PayPalResource.ConfigureAndExecute <WebhookEvent>(apiContext, HttpMethod.POST, resource, JsonConvert.SerializeObject(data), "", true);

            return(webhookEvent);
        }
Ejemplo n.º 19
0
        public void PayPalResourceEndpointDefaultTest()
        {
            var config = new Dictionary <string, string>();

            Assert.Equal(BaseConstants.RESTSandboxEndpoint, PayPalResource.GetEndpoint(config));
        }