Class: MyActiveMerchants::VoucherGbPrimepayGateway
- Inherits:
-
Object
- Object
- MyActiveMerchants::VoucherGbPrimepayGateway
- Includes:
- DefaultErrorContainer, ElasticAPM::SpanHelpers
- Defined in:
- app/my_lib/my_active_merchants/voucher_gb_primepay_gateway.rb
Class Method Summary collapse
Instance Method Summary collapse
- #charge(charge_amount) ⇒ Object
-
#initialize(voucher_transaction, card) ⇒ VoucherGbPrimepayGateway
constructor
A new instance of VoucherGbPrimepayGateway.
- #valid? ⇒ Boolean
-
#void(reference_no, gb_secret_key) ⇒ Object
use .void method for easy access.
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Constructor Details
#initialize(voucher_transaction, card) ⇒ VoucherGbPrimepayGateway
Returns a new instance of VoucherGbPrimepayGateway.
8 9 10 11 12 13 14 15 16 |
# File 'app/my_lib/my_active_merchants/voucher_gb_primepay_gateway.rb', line 8 def initialize(voucher_transaction, card) @voucher_transaction = voucher_transaction.presence || VoucherTransaction.new @card = if card.is_a?(ActionController::Parameters) card.permit!.to_h.with_indifferent_access elsif card.present? card.with_indifferent_access end BUSINESS_LOGGER.set_business_context({ voucher_transaction_id: @voucher_transaction.id, card: @card }) end |
Class Method Details
.void(reference_no, gb_secret_key = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'app/my_lib/my_active_merchants/voucher_gb_primepay_gateway.rb', line 52 def self.void(reference_no, gb_secret_key = nil) if gb_secret_key.nil? tmp_secret = RequestStore.store[GB_PRIMEPAY_SECRET_KEY] gb_secret_key = tmp_secret.presence || Figaro.env.GB_PRIMEPAY_SECRET_KEY! end client = ::MyActiveMerchants::VoucherGbPrimepayGateway.new(nil, nil) client.void(reference_no, gb_secret_key) end |
Instance Method Details
#charge(charge_amount) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/my_lib/my_active_merchants/voucher_gb_primepay_gateway.rb', line 28 def charge(charge_amount) unless valid? BUSINESS_LOGGER.info 'Credit card is invalid', voucher_transaction_id: voucher_transaction.id return false end attributes = charge_attribute(charge_amount) voucher_transaction.charges.build(attributes) external_charge_id = attributes[:omise_charge_id] gb_secret_key = RequestStore.store[GB_PRIMEPAY_SECRET_KEY] VoidFailedTransactionVoucherWorker.void_later(external_charge_id, gb_secret_key) (external_charge_id) check_payment_status(external_charge_id) BUSINESS_LOGGER.info 'Done processing voucher transactin with CC and 3d secure', voucher_transaction_id: voucher_transaction.id true end |
#valid? ⇒ Boolean
18 19 20 21 22 23 24 25 |
# File 'app/my_lib/my_active_merchants/voucher_gb_primepay_gateway.rb', line 18 def valid? if card.nil? errors.add :base, 'Token or Card is blank' return false end true end |
#void(reference_no, gb_secret_key) ⇒ Object
use .void method for easy access
63 64 65 66 67 68 69 70 |
# File 'app/my_lib/my_active_merchants/voucher_gb_primepay_gateway.rb', line 63 def void(reference_no, gb_secret_key) url = "#{::GB_PRIMEPAY_BASE_URL}v1/void" body = { gbpReferenceNo: reference_no } payload = body_to_payload(body, gb_secret_key) BUSINESS_LOGGER.info 'Voiding voucher transaction', reference_no: reference_no api_call(url, payload) end |