Skip to content

Instantly share code, notes, and snippets.

@jordanlewiz
Last active August 29, 2015 14:22
Show Gist options
  • Save jordanlewiz/66d38525852e9a9f587c to your computer and use it in GitHub Desktop.
Save jordanlewiz/66d38525852e9a9f587c to your computer and use it in GitHub Desktop.
Structure styleguide - example 'component'
# https://market.styleguide.envato.com/structures/checkout/payment_method
module Styleguide
class Content::Structures::Checkout::PaymentMethod
include Styleguide::Component
def partial
'buying/checkout/payment_method'
end
def default_wrapper_css
'-layout-main-content'
end
private
def presenter(options = {})
Styleguide::OpenPresenter.new(
{
:form => Styleguide::OpenForm.new,
:disabled? => false,
:just_saved? => false,
:add_credit_to_checkout? => false,
:credit_not_possible? => false,
:appropriate_credit_payment_key => 'prepaid::',
:unable_to_complete_purchase? => false,
:handling_fee? => false,
:handling_fee_amount => '$2',
:buyer_balance => '$45',
:paypal_outage? => false,
:paypal_outage_presenter => paypal_outage_presenter,
:paypal_payment_selected? => false,
:credit_payment_selected? => false,
:deposit_payment_selected? => false,
:braintree_payment_selected? => false,
:appropriate_credit_option_selected? => false,
:paypal_payment_key => 'buy_now::paypal',
:braintree_payment_key => 'buy_now::braintree',
:credit_card_payments_enabled? => false,
}.merge(options)
)
end
def paypal_outage_presenter(options = {})
Styleguide::OpenPresenter.new(
{
:gateway_name => 'PayPal',
:finish_time => Time.now + 3.hours
}.merge(options)
)
end
# Scenarios
scenario :payment_method_not_selected do
presenter
end
scenario :payment_method_just_saved do
presenter(
:credit_payment_selected? => true,
:appropriate_credit_option_selected? => true,
:just_saved? => true,
)
end
scenario :sufficient_credit do
presenter(
:credit_payment_selected? => true,
:appropriate_credit_option_selected? => true,
)
end
scenario :add_credit_to_checkout do
presenter(
:add_credit_to_checkout? => true,
:credit_payment_selected? => true,
:appropriate_credit_option_selected? => true,
:appropriate_credit_payment_key => 'deposit_and_buy::',
:buyer_balance => '$5',
)
end
scenario :add_credit_to_checkout_and_handling_fee_on_paypal do
presenter(
:add_credit_to_checkout? => true,
:credit_payment_selected? => true,
:appropriate_credit_option_selected? => true,
:appropriate_credit_payment_key => 'deposit_and_buy::',
:buyer_balance => '$5',
:handling_fee? => true,
)
end
scenario :credit_not_possible do
presenter(
:credit_not_possible? => true,
:appropriate_credit_payment_key => 'credit_not_possible',
:buyer_balance => '$5',
)
end
scenario :paypal_no_handling_fee do
presenter(
:paypal_payment_selected? => true,
)
end
scenario :paypal_with_handling_fee do
presenter(
:paypal_payment_selected? => true,
:handling_fee? => true,
)
end
scenario :paypal_outage do
presenter(
:paypal_outage? => true,
)
end
scenario :paypal_outage_credit_not_possible do
presenter(
:paypal_outage? => true,
:credit_not_possible? => true,
:appropriate_credit_payment_key => 'credit_not_possible',
:buyer_balance => '$5',
:unable_to_complete_purchase? => true,
)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment