Class: Workarea::GiftCards::Gateway
- Inherits:
-
Object
- Object
- Workarea::GiftCards::Gateway
- Defined in:
- lib/workarea/gift_cards/gateway.rb
Defined Under Namespace
Classes: Response
Instance Method Summary collapse
-
#authorize(amount, tender) ⇒ Workarea::GiftCards::Gateway::Response
See purchase.
-
#balance(token) ⇒ Money
Lookup the balance of one or many
Workarea::Payment::GiftCard
records. -
#cancel(amount, tender) ⇒ Workarea::GiftCards::Gateway::Response
See refund.
-
#capture(amount, tender) ⇒ Workarea::GiftCards::Gateway::Response
This gateway does a purchase on authorization so no capture is required.
-
#lookup(params) ⇒ Workarea::Payment::GiftCard?
Lookup a gift card.
-
#purchase(amount, tender) ⇒ Workarea::GiftCards::Gateway::Response
Perform a purchase on a
Workarea::Payment::GiftCard
. -
#refund(amount, tender) ⇒ Workarea::GiftCards::Gateway::Response
Undo a purchase on a
Workarea::Payment::GiftCard
. -
#uses_system_cards? ⇒ Boolean
Whether or not this gateway uses
Workarea::Payment::GiftCard
This controls the display of the admin menu, triggering the creation of cards from orders, and tracking redemptions.
Instance Method Details
#authorize(amount, tender) ⇒ Workarea::GiftCards::Gateway::Response
See purchase. This gateway performs a purchase on authorization.
26 27 28 |
# File 'lib/workarea/gift_cards/gateway.rb', line 26 def (amount, tender) purchase(amount, tender) end |
#balance(token) ⇒ Money
Lookup the balance of one or many Workarea::Payment::GiftCard
records. It will always return a single sum. If multiple numbers are provided, it returns the total of all balances. Invalid numbers return a balance of zero.
106 107 108 |
# File 'lib/workarea/gift_cards/gateway.rb', line 106 def balance(token) Array.wrap(token).sum(0.to_m) { |t| Payment::GiftCard.find_balance(t) } end |
#cancel(amount, tender) ⇒ Workarea::GiftCards::Gateway::Response
See refund.
37 38 39 |
# File 'lib/workarea/gift_cards/gateway.rb', line 37 def cancel(amount, tender) refund(amount, tender) end |
#capture(amount, tender) ⇒ Workarea::GiftCards::Gateway::Response
This gateway does a purchase on authorization so no capture is required.
48 49 50 51 |
# File 'lib/workarea/gift_cards/gateway.rb', line 48 def capture(amount, tender) # no op, captures on authorization Response.new(true, I18n.t('workarea.gift_cards.capture')) end |
#lookup(params) ⇒ Workarea::Payment::GiftCard?
Lookup a gift card.
118 119 120 121 122 123 124 125 |
# File 'lib/workarea/gift_cards/gateway.rb', line 118 def lookup(params) email = params.fetch(:email, nil) token = params.fetch(:token, nil) if email.present? && token.present? Workarea::Payment::GiftCard.find_by_token_and_email(token, email) end end |
#purchase(amount, tender) ⇒ Workarea::GiftCards::Gateway::Response
Perform a purchase on a Workarea::Payment::GiftCard
. This will increment the ‘used` field, and decrement the `balance` field.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/workarea/gift_cards/gateway.rb', line 61 def purchase(amount, tender) Payment::GiftCard.purchase(tender.number, amount) Response.new( true, I18n.t( 'workarea.gift_cards.debit', amount: amount, number: tender.number ) ) rescue Payment::InsufficientFunds Response.new(false, I18n.t('workarea.gift_cards.insufficient_funds')) end |
#refund(amount, tender) ⇒ Workarea::GiftCards::Gateway::Response
Undo a purchase on a Workarea::Payment::GiftCard
. This will increment the ‘balance` field, and decrement the `used` field.
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/workarea/gift_cards/gateway.rb', line 84 def refund(amount, tender) Payment::GiftCard.refund(tender.number, amount) Response.new( true, I18n.t( 'workarea.gift_cards.credit', amount: amount, number: tender.number ) ) end |
#uses_system_cards? ⇒ Boolean
Whether or not this gateway uses Workarea::Payment::GiftCard
This controls the display of the admin menu, triggering the creation of cards from orders, and tracking redemptions.
15 16 17 |
# File 'lib/workarea/gift_cards/gateway.rb', line 15 def uses_system_cards? true end |