how to link purchases to user records in another system? - shopify

sorry I posted this in the google group before I realized you had moved this type of question to stackoverflow
I'm developing a web app with an e-commerce component based on shopify as a white-labelled product for our clients. Our app allows our clients' customers to purchase a subscription to a product for use within the app. Each of our clients will have a separate shopify store. We have a web interface that allows our clients to create products and we use the shopify api to create the products in their store via an app. We have installed web hooks to receive notification of payments so that we can create the appropriate records in our system to allow the customer access to the product they purchased.
So far, the plan has been to provide a product list on our site with a 'Buy Now' button that adds the product to the store's cart and then direct the user to checkout using Shopify's checkout system. In the fulfillment web hook, we get the cart token so all we need to do to link the two systems is record the cart token temporarily in our customer database and then we can credit the right user with the purchase.
The problem that we are running in to is that there seems to be no way to link the cart / order / payment to the user that is actually logged in to our system. We are still under development so we are using test stores and the domain of the app is different from the domain of the store (and that may be the case in the production system too) and it is seemingly impossible to figure out how to link the two systems.
I have tried a couple of different approaches ...
1) use a form and post to the store's cart/add.js with a return_to=back
This seems successful in that the items are added to the cart and opening the cart in a new window takes them to the cart they added the item to, but there is no way to associate that cart with the user on our system since we can't access the cart token in a separate domain
2) use a proxy (our system is written in nodes) to post to the store's cart and intercept the cart token.
This also works in that an item is added to a cart and we can access the _session_id and cart cookies from the response, but I don't seem to be able to set those cookies in the browser. Going to the store's cart doesn't show the item just added and the store gets a different cart token.
Is there a different approach or should one of those work?
Should we be doing this entirely differently?
Cheers
Paul

Your best bet is to put something in cart attributes when the order is created and use that when you get the webhook to link the order to the other system. You could have a simple json endpoint on the other server to get back the currently logged in user, or have them enter some user is on the cart page and store them in the cart atributes. More on cart attributes http://wiki.shopify.com/Ask_customer_for_additional_information

To implement John's suggestion, I put the following into my cart.liquid file:
<script type="text/javascript">
(function($){
$(document).ready(function(){
$.ajax({
url: 'http://<server>/token',
dataType: 'jsonp',
success: function(data, status, xhr) {
$('#cartform').append('<input type="hidden" name="attributes[token]" value="'+data.token+'" />');
},
error: function(xhr, status, error) {
alert('Error');
}
});
});
})(jQuery);
</script>
My server runs on a different domain than the shop, so I'm using jsonp. The token is something I can use to uniquely identify a customer record in my database. I am using an attribute so that it doesn't conflict with our client's use of shopify's note feature if they want to use it themselves for something. I have not yet tested this with my web hook but I assume that I can make this work from here on.
I'm not completely satisfied with this as it requires that our clients put this into their templates in order for shopify to work with our system. I still think that there should be a way through the JSON /cart API to set the value of the note for a cart.

Related

Add product from external catalog and Spartacus cart

I have a scenario where we have an external web product catalog and user wants to Add the product from this external catalog to Spartacus cart.
The biggest constraint is the ext catalog (another software which cannot be customized) can only do a HTTP POST the payload containing multiple product ids, quantities, and other attributes through a callback URL. Since we are using Spartacus store-front, I don't think we can do a POST to a frontend endpoint like in accelerator. So that only gives us the option to POST to OCC API, which also brings troublesome for authentication, identify cart, etc. Is there any better solution/pattern?
If we can only update records via OCC, is there also a way to stream event to Spartacus to do cart refresh in UI?
Thanks for any suggestion!

How to add script to the front side of the shopify app

As i am new to shopify app i created an app and installed over a store with script tag having read and write permission . How can i dynamically add the javascript to the front side of shopify app.
Use the Script Tag API to create the javascript you want to load dynamically.
# POST /admin/script_tags.json
{
"script_tag": {
"event": "onload",
"src": "https://djavaskripped.org/fancy.js"
}
}
Documentation: Link
When your App is installed in a Shop, the merchant usually gets two dialogs to confirm. One is if you are asking for a billing charge. The other is for the scopes access to their shop. Assuming they approve both, you will get an oAuth token allowing you to read/write ScriptTag endpoint.
So when you get that oAuth token, you save it along with the shop name, and that is finally when you can POST your script tag payload in the store.

BigCommerce Customize checkout page

I'll be precise, i have been trying to add a custom gateway to bigcommerce, i have been somewhat successful till now, now i am stuck on bypassing the checkout page, i am unable to add additional option in checkout payment options, i'm able to do it using javascript, but then order is not being processed, and second thing, even if i am able to add option, and redirect user using javascript, how am i suppose to empty the cart once user has returned to the site?
I'm completely stuck here, any help or pointing to the right direction would be greatly appreciated.
For anyone who wish to achieve the same as i needed to, here is i went about it,
i didn't touch the actual flow of the order and checkout, what i did, i renamed one of the offline payment method as the third-party gateway i wanted to integrate, then after checkout, user lands of thank-you page, on thank-you page, i embedded my script, which picked up order-id from thank-you page, and checked the payment method that was used during checkout, if it matches the one i required, then i redirected user to external url ( additional domain on another hosting ), where user and order details were fetched using order_id ( which i sent via ajax ) and the payment was processed, and in the end, user is redirected back to the bigcommerce store.
Things that you will need
Additional domain
Additional hosting, to point that domain to, and to execute payment-gateway processing code and also to update order status in bigCommerce via their API.
It is kind of a complicated process, but once you get the hang of it, it becomes pretty simple after that.

how to access shopify Products via API without api-key and password?

i want to develop a chrome extension to see stats for any store which develop in shopify, can i access any store products without API-Key and Password in shopify?
No, you cant access products json without using api-key or permanent token of the store.
But still you want to access the product details you atleast needs the handler of the product.
Lets say your store is "abc.myshopify.com" and handler of your product is "xyz", then you can product json of xyz by HTTP GET call in following url
https://www.abc.myshopify.com/products/xyz.json
in general
https://www.[storename]/products/[product-handle].json
You could try using the Shopify StoreFront API.
It allows to get information of your shop from from your own website or custom app. Although it doesn't need a API Password, it needs a Api Key that doesn't need to be a secret.
The documentation says this (the first point is the important):
Using the Storefront API, you can:
Fetch data about a single product or a collection of products to
display on any website or device.
Create unique checkout experiences
with full control over the shopping cart.
Create new customers or
modify existing ones, including address information.
Allow customers
to select unique product options.
There is no way shopify will provide store details (product list) without api authentication.
For your requirement, I would suggest to create a shopify app which will sync all product details to your storage and you can access data from there.

how to proceed to checkout page after making order in bigcommerce?

I have created orders using Bigcommerce API for a web based app.
Now after creating the order, how do I make the user to proceed to Bigcommerce checkout page to make the payment?
thanks
If you are capturing an order via the API, you won't be able to direct the user to a checkout page to just capture payments. The order creation is more for POS kind of flow, where you can capture the payment externally and create an order associated with that product in your bigcommerce store, thereby managing inventory details, syncing orders, etc.