Class: Payment::Gateways::PurchaseOrder

Inherits:
BasePaymentGateway
  • Object
show all
Defined in:
app/services/payment/gateways/purchase_order.rb

Overview

Purchase-order gateway. Authorization just consumes the customer's
available credit (no external API); voiding replenishes it.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(payment, _delivery = nil) ⇒ PurchaseOrder

Returns a new instance of PurchaseOrder.



9
10
11
12
13
# File 'app/services/payment/gateways/purchase_order.rb', line 9

def initialize(payment, _delivery = nil)
  @payment = payment
  success = nil
  message = nil
end

Instance Method Details

#authorizePayment::Gateways::PurchaseOrder::Result

Mark the PO authorized and resync the billing customer's available
credit so the consumed amount is reflected.



19
20
21
22
23
# File 'app/services/payment/gateways/purchase_order.rb', line 19

def authorize
  @payment.payment_authorized!
  @payment.order.billing_entity.sync_credit_limit
  Result.new(success: true)
end

#void(report_fraud = false) ⇒ Payment::Gateways::PurchaseOrder::Result

Void an authorized PO and replenish the billing customer's
available credit.

Parameters:

  • report_fraud (Boolean) (defaults to: false)

    retained for parity with CC gateway

Returns:



30
31
32
33
34
35
36
37
# File 'app/services/payment/gateways/purchase_order.rb', line 30

def void(report_fraud = false)
  return Result.new(success: false) unless @payment.authorized?

  @payment.payment_voided!
  # Replenish Credit line
  @payment.order.billing_entity.sync_credit_limit if @payment.order.billing_entity
  Result.new(success: true)
end