Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jordanhudgens/528bbbf324826a6e2f7d8e56a5cb6a37 to your computer and use it in GitHub Desktop.
Save jordanhudgens/528bbbf324826a6e2f7d8e56a5cb6a37 to your computer and use it in GitHub Desktop.
class OrdersCreateJob < ActiveJob::Base
def create_usage_charge(product_name, price_to_merchant)
usage_charge = ShopifyAPI::UsageCharge.new(description: product_name, price: price_to_merchant.to_f)
recurring_application_charge = ShopifyAPI::RecurringApplicationCharge.current
usage_charge.prefix_options = { recurring_application_charge_id: recurring_application_charge.id }
usage_charge.save
end
def perform(shop_domain:, webhook:)
shop = Shop.find_by(shopify_domain: shop_domain)
shop.with_shopify_session do
customer = webhook['customer']
email = customer["email"]
full_name = "#{customer['first_name']} #{customer['first_name']}"
shop_hacker_merchant_id = ShopifyMerchant.find_by_shopify_id(ShopifyAPI::Shop.current.id).id
webhook['line_items'].each do |line_item|
if product = ShopProduct.find_by_shopify_product_id(line_item['product_id'])
products_service = ProductsService.new(shop_hacker_merchant_id)
shop_hacker_product = products_service.get_product(id: product.shop_hacker_product_id)
create_usage_charge(line_item['title'], shop_hacker_product['bundle_pricing'])
SalesService.new(
product,
full_name,
email,
shop_hacker_merchant_id
).create_sale
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment