/// <summary>
        /// Creates a new <see cref="ScriptTag"/> on the store.
        /// </summary>
        /// <param name="tag">A new <see cref="ScriptTag"/>. Id should be set to null.</param>
        /// <returns>The new <see cref="ScriptTag"/>.</returns>
        public virtual async Task <ScriptTag> CreateAsync(ScriptTag tag)
        {
            var req     = PrepareRequest("script_tags.json");
            var content = new JsonContent(new
            {
                script_tag = tag
            });

            return(await ExecuteRequestAsync <ScriptTag>(req, HttpMethod.Post, content, "script_tag"));
        }
        /// <summary>
        /// Updates the given <see cref="ScriptTag"/>.
        /// </summary>
        /// <param name="scriptTagId">Id of the object being updated.</param>
        /// <param name="tag">The <see cref="ScriptTag"/> to update.</param>
        /// <returns>The updated <see cref="ScriptTag"/>.</returns>
        public virtual async Task <ScriptTag> UpdateAsync(long scriptTagId, ScriptTag tag)
        {
            var req     = PrepareRequest($"script_tags/{scriptTagId}.json");
            var content = new JsonContent(new
            {
                script_tag = tag
            });

            return(await ExecuteRequestAsync <ScriptTag>(req, HttpMethod.Put, content, "script_tag"));
        }
Example #3
0
        /// <summary>
        /// Updates the given <see cref="ScriptTag"/>.
        /// </summary>
        /// <param name="scriptTagId">Id of the object being updated.</param>
        /// <param name="tag">The <see cref="ScriptTag"/> to update.</param>
        /// <param name="cancellationToken">Cancellation Token</param>
        /// <returns>The updated <see cref="ScriptTag"/>.</returns>
        public virtual async Task <ScriptTag> UpdateAsync(long scriptTagId, ScriptTag tag, CancellationToken cancellationToken = default)
        {
            var req     = PrepareRequest($"script_tags/{scriptTagId}.json");
            var content = new JsonContent(new
            {
                script_tag = tag
            });
            var response = await ExecuteRequestAsync <ScriptTag>(req, HttpMethod.Put, cancellationToken, content, "script_tag");

            return(response.Result);
        }
Example #4
0
        public async Task <ActionResult> Callback([FromQuery] string shop, [FromQuery] string hmac, [FromQuery] string code, [FromQuery] string state)
        {
            //Now retrieve the access token
            var apiKey      = _config["Shopify_API_Key"];
            var apiSecret   = _config["Shopify_Secret_Key"];
            var callbackUrl = _config["CallbackUrl"];

            string accessToken = await AuthorizationService.Authorize(code, shop, apiKey, apiSecret);

            //Add a script tag
            ScriptTagService svc = new ScriptTagService(shop, accessToken);
            var tag = new ShopifySharp.ScriptTag();

            tag.DisplayScope = "online_store";
            tag.Event        = "onload";
            tag.Src          = $"{callbackUrl}/js/Rda.Shopify.js";

            var createdTag = await svc.CreateAsync(tag);

            return(Ok());
        }