Purchasing products using the ShopifyAPI ruby gem that were discovered via the GraphQL Storefront API

Highlighted
New Member
1 0 0

I'm wondering if there's a way to use the ShopifyAPI ruby gem to create an order for product found using the GraphQL Storefront API.

We actually already allow a few products to be purchased through our custom Rails application. Since we're charging users via Stripe (for subscriptions that aren't available in our Shopify store), we also use Stripe to charge them for the Shopify purchase, and then we just tell Shopify that the cost of each line item should be $0 for this order and that the "financial_status" of the order is "paid."

What we'd like to do is allow product discovered in the Storefront API to be purchased "at zero cost" using the ShopifyAPI gem as described above. However, it seem the Storefront API itself doesn't allow the functionality we need (setting line item cost to $0, marking the order as "paid"), but also the `ShopifyAPI::LineItem` doesn't allow us to use the product variant IDs provided by the Shopfront GraphQL API. Neither way seems to work…

Is there any way to accomplish what we're after?

For added context, here's the general code we're currently using (but that doesn't work with variant ideas from GraphQL land):


attr_reader :user, :product_variants, :address_params

def order
  ShopifyAPI::Order.new(
    customer: customer,
    line_items: line_items,
    shipping_address: shipping_address,
    financial_status: "paid",
    inventory_behavior: "decrement_ignoring_policy"
  )
end

def customer
  ShopifyAPI::Customer.new(
    first_name: user.first_name,
    last_name: user.last_name,
    email: user.email
  )
end

def line_items
  product_variants.map do |variant|
    ShopifyAPI::LineItem.new(
      variant_id: variant.id,
      quantity: variant.quantity,
      price: 0
    )
  end
end

 

0 Likes