Skip to content

Instantly share code, notes, and snippets.

@braidn
Created September 13, 2016 18:50
Show Gist options
  • Save braidn/8ddeb3c4b43be2ee19ba996ac948917a to your computer and use it in GitHub Desktop.
Save braidn/8ddeb3c4b43be2ee19ba996ac948917a to your computer and use it in GitHub Desktop.
RSpec.shared_context 'shopify_shop' do
let(:refund_amount) { 100 }
let(:shopify_payment_method) do
gateway = Spree::Gateway::ShopifyGateway.new
gateway.set_preference(:api_key, ENV.fetch('SHOPIFY_API_KEY'))
gateway.set_preference(:password, ENV.fetch('SHOPIFY_PASSWORD'))
gateway.set_preference(:shop_name, ENV.fetch('SHOPIFY_SHOP_NAME'))
gateway
end
def mock_order_request(endpoint, extension)
url = "https://this-is-my-test-shop.myshopify.com/admin/#{endpoint}#{extension}"
body = JSON.parse(File.read("../data/#{endpoint}.#{extension}"))
stub_request(:get, url)
.with(body: body,
headers: { 'Content-Type' => 'text/json',
'Content-Length' => 1 })
end
def create_fulfilled_paid_shopify_order
order = ShopifyAPI::Order.new
order.email = 'cab@godynamo.com'
order.test = true
order.fulfillment_status = 'fulfilled'
order.line_items = [
{
variant_id: '447654529',
quantity: 1,
name: 'test',
price: refund_amount,
title: 'title'
}
]
order.customer = { first_name: 'Paul',
last_name: 'Norman',
email: 'paul.norman@example.com' }
order.billing_address = {
first_name: 'John',
last_name: 'Smith',
address1: '123 Fake Street',
phone: '555-555-5555',
city: 'Fakecity',
province: 'Ontario',
country: 'Canada',
zip: 'K2P 1L4'
}
order.shipping_address = {
first_name: 'John',
last_name: 'Smith',
address1: '123 Fake Street',
phone: '555-555-5555',
city: 'Fakecity',
province: 'Ontario',
country: 'Canada',
zip: 'K2P 1L4'
}
order.transactions = [
{
kind: 'capture',
status: 'success',
amount: refund_amount
}
]
order.financial_status = 'paid'
order.save
order
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment