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) ⇒ Object
- .retrieve(id:, client: Squake::Client.new) ⇒ Object
Class Method Details
.cancel(id:, client: Squake::Client.new) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/squake/purchase.rb', line 84 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) ⇒ 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 |
# 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) result = client.call( path: ENDPOINT, method: :post, 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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/squake/purchase.rb', line 58 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 |