Skip to content

Instantly share code, notes, and snippets.

@staycreativedesign
Last active May 10, 2019 22:19
Show Gist options
  • Save staycreativedesign/e87bbfedc24b1ad50c0d97647bd5a99f to your computer and use it in GitHub Desktop.
Save staycreativedesign/e87bbfedc24b1ad50c0d97647bd5a99f to your computer and use it in GitHub Desktop.
How come my SKU description does not appear in the order? Jews for Judaism Charity Poker Tournament appears instead of Bar Sponsor
class CreateOrderService
def initialize(current_user, params)
@customer = current_user
@params = params
@single_player_qty = params[:single_player_quantity]
@double_stack_qty = params[:double_stack_quantity]
@non_player_qty = params[:non_player_quantity]
@sponsor = params[:sponsor]
end
def call
order = create_order
pay_order(order)
end
def create_order
puts @single_player_qty
puts @double_stack_qty
puts @non_player_qty
order = Stripe::Order.create({
currency: 'usd',
customer: @customer.stripe_id,
items: [
single_player_tickets(@single_player_qty),
double_stack_tickets(@double_stack_qty),
non_player_tickets(@non_player_qty),
sponsor(@sponsor)
].compact,
email: @customer.email
})
end
def pay_order(order)
order = Stripe::Order.pay(
order.id,
{
customer: @customer.stripe_id
}
)
end
private
def test_mode_or_live_mode
if Rails.env.development?
@dsb = "sku_F1aNISdiBCzjeo"
@npt = "sku_F27GZMvVX6LHga"
@spt = "sku_F27HglSdjt6NLf"
else
@dsb = "sku_F2LAay0jR8FuuG"
@npt = "sku_F2LA9zrGaOx5Qj"
@spt = "sku_F2LA9OZlxqZ0RL"
end
end
def single_player_tickets(qty = 0)
test_mode_or_live_mode
puts "this is the sinple player qty " + qty
if qty.to_i > 0
{
type: 'sku',
description: 'Single Player Ticket',
parent: @spt,
quantity: qty
}
end
end
def double_stack_tickets(qty = 0)
test_mode_or_live_mode
if qty.to_i > 0
{
type: 'sku',
description: 'Double Stack Addons',
parent: @dsb,
quantity: qty,
}
end
end
def non_player_tickets(qty = 0)
test_mode_or_live_mode
if qty.to_i > 0
{
type: 'sku',
description: 'Non Player Tickets',
parent: @npt,
quantity: qty,
}
end
end
def sponsor(sku)
if !sku == '0'
{
type: 'sku',
description: 'Sponsorship',
parent: sku,
quantity: 1,
}
end
end
end
POST /v1/orders/or_1EYHMnLe7Ukzj8AajJ1LH5nU
{
"id": "foobar",
"object": "order",
"amount": 100,
"amount_returned": null,
"application": null,
"application_fee": null,
"charge": "fooo",
"created": 1557427997,
"currency": "usd",
"customer": "cus_F2M4gcGtwmjn68",
"email": "[email protected]",
"items": [
{
"object": "order_item",
"amount": 100,
"currency": "usd",
"description": "Jews for Judaism Charity Poker Tournament",
"parent": "sku_F2LFByvmamDFxR",
"quantity": 1,
"type": "sku"
},
{
"object": "order_item",
"amount": 0,
"currency": "usd",
"description": "Taxes (included)",
"parent": null,
"quantity": null,
"type": "tax"
},
{
"object": "order_item",
"amount": 0,
"currency": "usd",
"description": "Free shipping",
"parent": "ship_free-shipping",
"quantity": null,
"type": "shipping"
}
],
"livemode": true,
"metadata": {
},
"returns": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/order_returns?order=or_1EYHMnLe7Ukzj8AajJ1LH5nU"
},
"selected_shipping_method": "ship_free-shipping",
"shipping": null,
"shipping_methods": [
{
"id": "ship_free-shipping",
"amount": 0,
"currency": "usd",
"delivery_estimate": null,
"description": "Free shipping"
}
],
"status": "paid",
"status_transitions": {
"canceled": null,
"fulfiled": null,
"paid": 1557427998,
"returned": null
},
"updated": 1557427998
}
When logged in to my account
https://stripe.com/docs/api/orders/object
why are the descriptions of the skus tha name of the product?
{
"id": "or_1EYENnLe7Ukzj8AajebcRF24",
"object": "order",
"amount": 404000,
"amount_returned": null,
"application": null,
"application_fee": null,
"charge": null,
"created": 1557416527,
"currency": "usd",
"customer": "cus_F2IzGkriXpOTbG",
"email": "[email protected]",
"items": [
{
"object": "order_item",
"amount": 50000,
"currency": "usd",
"description": "Jews for Judaism Charity Poker Tournament",
"parent": "sku_F1aNISdiBCzjeo",
"quantity": 2,
"type": "sku"
},
{
"object": "order_item",
"amount": 54000,
"currency": "usd",
"description": "Jews for Judaism Charity Poker Tournament",
"parent": "sku_F27HglSdjt6NLf",
"quantity": 3,
"type": "sku"
},
{
"object": "order_item",
"amount": 300000,
"currency": "usd",
"description": "Jews for Judaism Charity Poker Tournament",
"parent": "sku_F27IY9RdkjCV7n",
"quantity": 1,
"type": "sku"
},
{
{
"id": "sku_F2LFByvmamDFxR",
"object": "sku",
"active": true,
"attributes": {
"name": "Bar Sponsor"
},
"created": 1557373028,
"currency": "usd",
"image": null,
"inventory": {
"quantity": null,
"type": "infinite",
"value": null
},
"livemode": false,
"metadata": {},
"package_dimensions": null,
"price": 200000,
"product": "prod_F1aMfpDAyy19yQ",
"updated": 1557373028
}
items.description
string
Description of the line item, meant to be displayable to the user (e.g., "Express shipping").
Stripe::Order.create({
currency: 'usd',
customer: "cus_F2MYGvU2FlfkVa",
items: [
{
type: 'sku',
description: 'Non Player Tickets',
parent: "sku_F27GZMvVX6LHga",
quantity: 1,
}
]
})
#Test Order returns
=> #<Stripe::Order:0x3fc00f4a3670 id=or_1EYQbCLe7Ukzj8AafEZnVh3B> JSON: {
"id": "or_1EYQbCLe7Ukzj8AafEZnVh3B",
"object": "order",
"amount": 15000,
"amount_returned": null,
"application": null,
"application_fee": null,
"charge": null,
"created": 1557463486,
"currency": "usd",
"customer": "cus_F2MYGvU2FlfkVa",
"email": "[email protected]",
"items": [
{"object":"order_item","amount":15000,"currency":"usd","description":"Jews for Judaism Charity Poker Tournament","parent":"sku_F27GZMvVX6LHga","quantity":1,"type":"sku"},
{"object":"order_item","amount":0,"currency":"usd","description":"Taxes (included)","parent":null,"quantity":null,"type":"tax"},
{"object":"order_item","amount":0,"currency":"usd","description":"Free shipping","parent":"ship_free-shipping","quantity":null,"type":"shipping"}
],
"livemode": false,
"metadata": {},
"returns": {"object":"list","data":[],"has_more":false,"total_count":0,"url":"/v1/order_returns?order=or_1EYQbCLe7Ukzj8AafEZnVh3B"},
"selected_shipping_method": "ship_free-shipping",
"shipping": null,
"shipping_methods": [
{"id":"ship_free-shipping","amount":0,"currency":"usd","delivery_estimate":null,"description":"Free shipping"}
],
"status": "created",
"status_transitions": {"canceled":null,"fulfiled":null,"paid":null,"returned":null},
"updated": 1557463486
}
@snuggs
Copy link

snuggs commented May 10, 2019

I'd actually re-architect data model to have name NOT be a composed object within attributes.
Can we make this a top level property?

Look forward to speaking with you!

@staycreativedesign
Copy link
Author

staycreativedesign commented May 10, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment