Class: PaymentMethod::Webpay
- Inherits:
-
PaymentMethod
- Object
- PaymentMethod
- PaymentMethod::Webpay
- Defined in:
- app/models/spree/payment_method/webpay.rb
Overview
not precise notation, but required for Rails convention
Constant Summary collapse
- CVC_CODE_TRANSLATOR =
Payment related methods ================ Options are ignored unless they are mentioned in parameters list.
{ 'pass' => 'M', 'fail' => 'N', 'unchecked' => 'P' }
Instance Method Summary collapse
-
#authorize(money, paysource, options = {}) ⇒ Object
Performs an authorization, which reserves the funds on the customer’s credit card, but does not charge the card.
-
#capture(money, authorization, options = {}) ⇒ Object
Captures the funds from an authorized transaction.
- #create_profile(payment) ⇒ Object
- #credit(money, source, identification, options = {}) ⇒ Object
- #method_type ⇒ Object
- #payment_profiles_supported? ⇒ Boolean
-
#payment_source_class ⇒ Object
Meta ================.
-
#purchase(money, paysource, options = {}) ⇒ Object
Perform a purchase, which is essentially an authorization and capture in a single operation.
-
#refund(money, _source, identification, options = {}) ⇒ Object
Refund a transaction.
-
#reusable_sources(order) ⇒ Object
Copied from spree-core gateway.rb.
- #source_required? ⇒ Boolean
- #supports?(source) ⇒ Boolean
-
#void(authorization, _source, options = {}) ⇒ Object
Void a previous transaction.
Instance Method Details
#authorize(money, paysource, options = {}) ⇒ Object
Performs an authorization, which reserves the funds on the customer’s credit card, but does not charge the card.
Parameters
-
money– The amount to be authorized as an Integer value in cents. -
paysource– The CreditCard or Check details for the transaction.
68 69 70 |
# File 'app/models/spree/payment_method/webpay.rb', line 68 def (money, paysource, = {}) create_charge(money, paysource, false) end |
#capture(money, authorization, options = {}) ⇒ Object
Captures the funds from an authorized transaction.
Parameters
-
money– The amount to be captured as an Integer value in cents. -
authorization– The authorization returned from the previous authorize request.
88 89 90 |
# File 'app/models/spree/payment_method/webpay.rb', line 88 def capture(money, , = {}) wrap_in_active_merchant_response { client.charge.capture(id: , amount: money) } end |
#create_profile(payment) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/models/spree/payment_method/webpay.rb', line 121 def create_profile(payment) return if payment.source.gateway_customer_profile_id.present? begin customer = client.customer.create( email: payment.order.email, description: payment.order.name, card: payment.source.gateway_payment_profile_id, ) payment.source.update_attributes!({ gateway_customer_profile_id: customer.id, gateway_payment_profile_id: nil }) rescue WebPay::ApiError => e payment.send(:gateway_error, e.respond_to?(:data) ? e.data.error. : e.) end end |
#credit(money, source, identification, options = {}) ⇒ Object
117 118 119 |
# File 'app/models/spree/payment_method/webpay.rb', line 117 def credit(money, source, identification, = {}) refund(money, source, identification, ) end |
#method_type ⇒ Object
14 15 16 |
# File 'app/models/spree/payment_method/webpay.rb', line 14 def method_type 'webpay' end |
#payment_profiles_supported? ⇒ Boolean
18 19 20 |
# File 'app/models/spree/payment_method/webpay.rb', line 18 def payment_profiles_supported? true end |
#payment_source_class ⇒ Object
Meta ================
10 11 12 |
# File 'app/models/spree/payment_method/webpay.rb', line 10 def payment_source_class CreditCard end |
#purchase(money, paysource, options = {}) ⇒ Object
Perform a purchase, which is essentially an authorization and capture in a single operation.
Parameters
-
money– The amount to be purchased as an Integer value in cents. -
paysource– The CreditCard or Check details for the transaction.
78 79 80 |
# File 'app/models/spree/payment_method/webpay.rb', line 78 def purchase(money, paysource, = {}) create_charge(money, paysource, true) end |
#refund(money, _source, identification, options = {}) ⇒ Object
Refund a transaction.
This transaction indicates to the gateway that money should flow from the merchant to the customer.
Parameters
-
money– The amount to be credited to the customer as an Integer value. -
identification– The ID of the original transaction against which the refund is being issued.
110 111 112 113 114 115 |
# File 'app/models/spree/payment_method/webpay.rb', line 110 def refund(money, _source, identification, = {}) wrap_in_active_merchant_response do charge = client.charge.retrieve(identification) client.charge.refund(id: identification, amount: charge.amount.to_i - charge.amount_refunded.to_i - money) end end |
#reusable_sources(order) ⇒ Object
Copied from spree-core gateway.rb
27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/spree/payment_method/webpay.rb', line 27 def reusable_sources(order) if order.completed? sources_by_order order else if order.user_id self.credit_cards.where(user_id: order.user_id).with_payment_profile else [] end end end |
#source_required? ⇒ Boolean
22 23 24 |
# File 'app/models/spree/payment_method/webpay.rb', line 22 def source_required? true end |
#supports?(source) ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/spree/payment_method/webpay.rb', line 39 def supports?(source) @account_info ||= client.account.retrieve brand_name = case source.brand when 'visa' then 'Visa' when 'master' then 'MasterCard' when 'diners_club' then 'Diners Club' when 'american_express' then 'American Express' when 'discover' then 'Discover' when 'jcb' then 'JCB' end @account_info.card_types_supported.include?(brand_name) end |
#void(authorization, _source, options = {}) ⇒ Object
Void a previous transaction
Parameters
-
authorization- The authorization returned from the previous authorize request.
97 98 99 |
# File 'app/models/spree/payment_method/webpay.rb', line 97 def void(, _source, = {}) wrap_in_active_merchant_response { client.charge.refund() } end |