Module: Jamm::Payment
- Defined in:
- lib/jamm/payment.rb
Class Method Summary collapse
- .get(charge_id, merchant: nil) ⇒ Object
- .list(customer:, pagination: nil, merchant: nil) ⇒ Object
- .off_session(customer:, charge:, merchant: nil) ⇒ Object
-
.off_session_async(customer:, charge:, idempotency_key: nil, merchant: nil) ⇒ Object
Auto-fills idempotency_key with a UUID when the caller did not supply one, so every async charge is retry-safe by default.
- .on_session(charge: nil, redirect: nil, customer: nil, buyer: nil, one_time: false, merchant: nil) ⇒ Object
- .refund(request, merchant: nil) ⇒ Object
Class Method Details
.get(charge_id, merchant: nil) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/jamm/payment.rb', line 77 def self.get(charge_id, merchant: nil) handler = Jamm::Client.handler(merchant: merchant) Jamm::OpenAPI::PaymentApi.new(handler).get_charge(charge_id) rescue Jamm::OpenAPI::ApiError => e return nil if e.code == 404 raise Jamm::ApiError.from_error(e) end |
.list(customer:, pagination: nil, merchant: nil) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/jamm/payment.rb', line 94 def self.list(customer:, pagination: nil, merchant: nil) handler = Jamm::Client.handler(merchant: merchant) Jamm::OpenAPI::PaymentApi.new(handler).get_charges(customer, pagination.nil? ? {} : pagination) rescue Jamm::OpenAPI::ApiError => e if [404].include?(e.code) nil else { charges: [] } end end |
.off_session(customer:, charge:, merchant: nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jamm/payment.rb', line 42 def self.off_session(customer:, charge:, merchant: nil) request = Jamm::OpenAPI::OffSessionPaymentRequest.new( customer: customer, charge: charge ) handler = Jamm::Client.handler(merchant: merchant) Jamm::OpenAPI::PaymentApi.new(handler).off_session_payment(request) rescue Jamm::OpenAPI::ApiError => e raise Jamm::ApiError.from_error(e) end |
.off_session_async(customer:, charge:, idempotency_key: nil, merchant: nil) ⇒ Object
Auto-fills idempotency_key with a UUID when the caller did not supply one, so every async charge is retry-safe by default. A caller-supplied key is left untouched so explicit retries reuse the same value.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/jamm/payment.rb', line 57 def self.off_session_async(customer:, charge:, idempotency_key: nil, merchant: nil) key = if idempotency_key.nil? || idempotency_key.strip.empty? SecureRandom.uuid else idempotency_key end request = Jamm::OpenAPI::OffSessionPaymentAsyncRequest.new( customer: customer, charge: charge, idempotency_key: key ) handler = Jamm::Client.handler(merchant: merchant) Jamm::OpenAPI::PaymentApi.new(handler).async_off_session_payment(request) rescue Jamm::OpenAPI::ApiError => e raise Jamm::ApiError.from_error(e) end |
.on_session(charge: nil, redirect: nil, customer: nil, buyer: nil, one_time: false, merchant: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jamm/payment.rb', line 11 def self.on_session( charge: nil, redirect: nil, customer: nil, buyer: nil, one_time: false, # Platform can set merchant id to call on behalf of the merchant. merchant: nil ) request = if customer.nil? Jamm::OpenAPI::OnSessionPaymentRequest.new( buyer: buyer, charge: charge, redirect: redirect, one_time: one_time ) else Jamm::OpenAPI::OnSessionPaymentRequest.new( customer: customer, charge: charge, redirect: redirect, one_time: one_time ) end handler = Jamm::Client.handler(merchant: merchant) Jamm::OpenAPI::PaymentApi.new(handler).on_session_payment(request) rescue Jamm::OpenAPI::ApiError => e raise Jamm::ApiError.from_error(e) end |
.refund(request, merchant: nil) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/jamm/payment.rb', line 87 def self.refund(request, merchant: nil) handler = Jamm::Client.handler(merchant: merchant) Jamm::OpenAPI::PaymentApi.new(handler).refund(request) rescue Jamm::OpenAPI::ApiError => e raise Jamm::ApiError.from_error(e) end |