Class: Hps::HpsGiftCardService
- Inherits:
-
HpsService
- Object
- HpsService
- Hps::HpsGiftCardService
- Defined in:
- lib/hps/services/hps_gift_card_service.rb
Instance Attribute Summary
Attributes inherited from HpsService
Instance Method Summary collapse
- #activate(giftcard, amount, currency = "USD") ⇒ Object
-
#add_value(giftcard, amount, currency = "USD") ⇒ Object
activate.
-
#balance(giftcard) ⇒ Object
add_value.
-
#deactivate(giftcard) ⇒ Object
balance.
-
#replace(old_card, new_card) ⇒ Object
deactivate.
-
#reverse(giftcard, amount) ⇒ Object
void.
-
#reward(giftcard, amount, currency = "USD", gratuity = nil, tax = nil) ⇒ Object
replace.
-
#sale(giftcard, amount, currency = "USD", gratuity = nil, tax = nil) ⇒ Object
reward.
-
#void(txn_id) ⇒ Object
sale.
Methods inherited from HpsService
#doTransaction, #gateway_url_for_key, #hydrate_transaction_header, #initialize
Constructor Details
This class inherits a constructor from Hps::HpsService
Instance Method Details
#activate(giftcard, amount, currency = "USD") ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hps/services/hps_gift_card_service.rb', line 3 def activate(giftcard, amount, currency = "USD") HpsInputValidation.check_amount(amount) txn_type = "GiftCardActivate" xml = Builder::XmlMarkup.new xml.hps :Transaction do xml.hps txn_type.to_sym do xml.hps :Block1 do xml.hps :Amt, amount if giftcard.is_a? HpsTokenData card_data = HpsGiftCard.new card_data.token_value = giftcard.token_value else card_data = giftcard end hydrate_gift_card_data(giftcard, xml) end end end submit_transaction(xml.target!, txn_type) end |
#add_value(giftcard, amount, currency = "USD") ⇒ Object
activate
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/hps/services/hps_gift_card_service.rb', line 27 def add_value(giftcard, amount, currency = "USD") HpsInputValidation.check_amount(amount) txn_type = "GiftCardAddValue" xml = Builder::XmlMarkup.new xml.hps :Transaction do xml.hps txn_type.to_sym do xml.hps :Block1 do xml.hps :Amt, amount if giftcard.is_a? HpsTokenData card_data = HpsGiftCard.new card_data.token_value = giftcard.token_value else card_data = giftcard end hydrate_gift_card_data(giftcard, xml) end end end submit_transaction(xml.target!, txn_type) end |
#balance(giftcard) ⇒ Object
add_value
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/hps/services/hps_gift_card_service.rb', line 51 def balance(giftcard) txn_type = "GiftCardBalance" xml = Builder::XmlMarkup.new xml.hps :Transaction do xml.hps txn_type.to_sym do xml.hps :Block1 do if giftcard.is_a? HpsTokenData card_data = HpsGiftCard.new card_data.token_value = giftcard.token_value else card_data = giftcard end hydrate_gift_card_data(giftcard, xml) end end end submit_transaction(xml.target!, txn_type) end |
#deactivate(giftcard) ⇒ Object
balance
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/hps/services/hps_gift_card_service.rb', line 73 def deactivate(giftcard) txn_type = "GiftCardDeactivate" xml = Builder::XmlMarkup.new xml.hps :Transaction do xml.hps txn_type.to_sym do xml.hps :Block1 do if giftcard.is_a? HpsTokenData card_data = HpsGiftCard.new card_data.token_value = giftcard.token_value else card_data = giftcard end hydrate_gift_card_data(giftcard, xml) end end end submit_transaction(xml.target!, txn_type) end |
#replace(old_card, new_card) ⇒ Object
deactivate
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/hps/services/hps_gift_card_service.rb', line 95 def replace(old_card, new_card) txn_type = "GiftCardReplace" xml = Builder::XmlMarkup.new xml.hps :Transaction do xml.hps txn_type.to_sym do xml.hps :Block1 do hydrate_gift_card_data(old_card, xml, 'OldCardData') hydrate_gift_card_data(new_card, xml, 'NewCardData') end end end submit_transaction(xml.target!, txn_type) end |
#reverse(giftcard, amount) ⇒ Object
void
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/hps/services/hps_gift_card_service.rb', line 200 def reverse(giftcard, amount) HpsInputValidation.check_amount(amount) txn_type = "GiftCardReversal" xml = Builder::XmlMarkup.new xml.hps :Transaction do xml.hps txn_type.to_sym do xml.hps :Block1 do xml.hps :Amt, amount if giftcard.is_a? HpsTokenData xml.hps :TokenValue, giftcard.token_value elsif giftcard.is_a? HpsGiftCard card_data = giftcard hydrate_gift_card_data(card_data, xml) else xml.hps :GatewayTxnId, giftcard end end end end submit_transaction(xml.target!, txn_type) end |
#reward(giftcard, amount, currency = "USD", gratuity = nil, tax = nil) ⇒ Object
replace
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/hps/services/hps_gift_card_service.rb', line 112 def reward(giftcard, amount, currency = "USD", gratuity = nil, tax = nil) HpsInputValidation.check_amount(amount) txn_type = "GiftCardReward" xml = Builder::XmlMarkup.new xml.hps :Transaction do xml.hps txn_type.to_sym do xml.hps :Block1 do xml.hps :Amt, amount if giftcard.is_a? HpsTokenData card_data = HpsGiftCard.new card_data.token_value = giftcard.token_value else card_data = giftcard end hydrate_gift_card_data(giftcard, xml) if ["USD", "POINTS"].include? currency.upcase xml.hps :Currency, currency.upcase end if gratuity xml.hps :GratuityAmtInfo, gratuity end if tax xml.hps :TaxAmtInfo, tax end end end end submit_transaction(xml.target!, txn_type) end |
#sale(giftcard, amount, currency = "USD", gratuity = nil, tax = nil) ⇒ Object
reward
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/hps/services/hps_gift_card_service.rb', line 149 def sale(giftcard, amount, currency = "USD", gratuity = nil, tax = nil) HpsInputValidation.check_amount(amount) txn_type = "GiftCardSale" xml = Builder::XmlMarkup.new xml.hps :Transaction do xml.hps txn_type.to_sym do xml.hps :Block1 do xml.hps :Amt, amount if giftcard.is_a? HpsTokenData card_data = HpsGiftCard.new card_data.token_value = giftcard.token_value else card_data = giftcard end hydrate_gift_card_data(giftcard, xml) if ["USD", "POINTS"].include? currency.upcase xml.hps :Currency, currency.upcase end if gratuity xml.hps :GratuityAmtInfo, gratuity end if tax xml.hps :TaxAmtInfo, tax end end end end submit_transaction(xml.target!, txn_type) end |
#void(txn_id) ⇒ Object
sale
186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/hps/services/hps_gift_card_service.rb', line 186 def void(txn_id) txn_type = "GiftCardVoid" xml = Builder::XmlMarkup.new xml.hps :Transaction do xml.hps txn_type.to_sym do xml.hps :Block1 do xml.hps :GatewayTxnId, txn_id end end end submit_transaction(xml.target!, txn_type) end |