Skip to content

Instantly share code, notes, and snippets.

@andreapavoni
Created October 2, 2015 15:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andreapavoni/a8cf533908062cfd9836 to your computer and use it in GitHub Desktop.
Save andreapavoni/a8cf533908062cfd9836 to your computer and use it in GitHub Desktop.
# Create a product
product_params = %{
description: "some content",
name: "some content",
price: 120.5,
sku: "ABC-123"
}
{:ok, product} = Nova.ProductCommands.create(product_params)
# Create a variant
variant_params = %{
price: 120.5,
sku: "SKU-ABC-123",
product_id: product.id
}
{:ok, variant} = Nova.VariantCommands.create(variant_params)
# Initialize a new order
{:ok, order} = Nova.OrderCommands.create
# Add a line item to order
{:ok, order, line_item} = Nova.OrderCommands.add_line_item(order.id, variant.id, 1)
# Do checkout
billing_params = %{
"billing_address" => %{
"street1" => "example street1",
"street2" => "example street2",
"city" => "Testville",
"region" => "Region",
"country" => "IT",
"postal_code" => "12345"
},
"credit_card" => %{
"name" => "John Doe",
"number" => "4111111111111111",
"month" => "10",
"year" => "2019",
"cvc" => "123"
}
}
{:ok, order, result} = Nova.Cart.checkout(order, :billing, billing_params)
IO.inspect result
# => %Commerce.Billing.Response{authorization: "3531738473", avs_result: nil,
# code: nil, cvc_result: nil, raw: nil, reason: nil, success: true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment