Class: Squake::Purchase
- Inherits:
-
Object
- Object
- Squake::Purchase
- Extended by:
- T::Sig
- Defined in:
- lib/squake/purchase.rb
Constant Summary collapse
- ENDPOINT =
T.let('/v2/purchases', String)
Class Method Summary collapse
- .cancel(id:, client: Squake::Client.new) ⇒ Object
- .create(pricing:, confirmation_document: nil, certificate_document: nil, metadata: nil, external_reference: SecureRandom.uuid, expand: [], client: Squake::Client.new, request_id: nil) ⇒ Object
- .retrieve(id:, client: Squake::Client.new) ⇒ Object
Class Method Details
.cancel(id:, client: Squake::Client.new) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/squake/purchase.rb', line 87 def self.cancel(id:, client: Squake::Client.new) result = client.call( path: "#{ENDPOINT}/#{id}/cancel", method: :post, ) return nil if result.code == 404 if result.success? purchase = Squake::Model::Purchase.from_api_response( T.cast(result.body, T::Hash[Symbol, T.untyped]), ) Return.new(result: purchase) else error = Squake::Errors::APIErrorResult.new( code: :"api_error_#{result.code}", detail: result., ) Return.new(errors: [error]) end end |
.create(pricing:, confirmation_document: nil, certificate_document: nil, metadata: nil, external_reference: SecureRandom.uuid, expand: [], client: Squake::Client.new, request_id: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/squake/purchase.rb', line 23 def self.create( pricing:, confirmation_document: nil, certificate_document: nil, metadata: nil, external_reference: SecureRandom.uuid, expand: [], client: Squake::Client.new, request_id: nil ) result = client.call( path: ENDPOINT, method: :post, headers: { 'X-Request-Id' => request_id }.compact, params: { pricing: pricing, confirmation_document: confirmation_document, certificate_document: certificate_document, metadata: , external_reference: external_reference, expand: , }, ) if result.success? purchase = Squake::Model::Purchase.from_api_response( T.cast(result.body, T::Hash[Symbol, T.untyped]), ) Return.new(result: purchase) else error = Squake::Errors::APIErrorResult.new( code: :"api_error_#{result.code}", detail: result., ) Return.new(errors: [error]) end end |
.retrieve(id:, client: Squake::Client.new) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/squake/purchase.rb', line 61 def self.retrieve(id:, client: Squake::Client.new) result = client.call( path: "#{ENDPOINT}/#{id}", ) return nil if result.code == 404 if result.success? purchase = Squake::Model::Purchase.from_api_response( T.cast(result.body, T::Hash[Symbol, T.untyped]), ) Return.new(result: purchase) else error = Squake::Errors::APIErrorResult.new( code: :"api_error_#{result.code}", detail: result., ) Return.new(errors: [error]) end end |