Class: Myrr::Wallet
- Inherits:
-
Object
- Object
- Myrr::Wallet
- Defined in:
- lib/myrr/wallet.rb
Overview
Wallet client for the Myrr protocol server.
Instance Attribute Summary collapse
-
#agent_did ⇒ Object
readonly
Returns the value of attribute agent_did.
-
#balance ⇒ Object
readonly
Returns the value of attribute balance.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#stripe_customer_id ⇒ Object
readonly
Returns the value of attribute stripe_customer_id.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Class Method Summary collapse
- .client ⇒ Object
-
.create(agent_did:, metadata: {}, client: nil) ⇒ Myrr::Wallet
Create a new wallet for the given agent.
-
.find(id, client: nil) ⇒ Myrr::Wallet?
Find a wallet by its UUID.
-
.find_by_agent(agent_did, client: nil) ⇒ Myrr::Wallet?
Find a wallet by its agent did:myrr: identifier.
Instance Method Summary collapse
-
#cards ⇒ Array<Myrr::Card>
List virtual cards for this wallet.
-
#fund(amount_cents:) ⇒ String
Create a Stripe Checkout session to fund this wallet.
-
#initialize(attrs) ⇒ Wallet
constructor
A new instance of Wallet.
-
#topup(seller_did:, seller_name:, amount_cents:, payment_intent_id: nil, metadata: {}) ⇒ Hash
Pre-approve a Myrr Pay top-up before confirming the PaymentIntent.
-
#transactions(limit: 20, before: nil) ⇒ Array<Myrr::Transaction>
List transactions for this wallet.
Constructor Details
#initialize(attrs) ⇒ Wallet
Returns a new instance of Wallet.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/myrr/wallet.rb', line 22 def initialize(attrs) @id = attrs["id"] @agent_did = attrs["agent_did"] @balance = attrs["balance"] @currency = attrs["currency"] || "usd" @status = attrs["status"] @stripe_customer_id = attrs["stripe_customer_id"] @metadata = attrs["metadata"] @created_at = attrs["created_at"] @updated_at = attrs["updated_at"] end |
Instance Attribute Details
#agent_did ⇒ Object (readonly)
Returns the value of attribute agent_did.
18 19 20 |
# File 'lib/myrr/wallet.rb', line 18 def agent_did @agent_did end |
#balance ⇒ Object (readonly)
Returns the value of attribute balance.
18 19 20 |
# File 'lib/myrr/wallet.rb', line 18 def balance @balance end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
18 19 20 |
# File 'lib/myrr/wallet.rb', line 18 def created_at @created_at end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
18 19 20 |
# File 'lib/myrr/wallet.rb', line 18 def currency @currency end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
18 19 20 |
# File 'lib/myrr/wallet.rb', line 18 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
18 19 20 |
# File 'lib/myrr/wallet.rb', line 18 def @metadata end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
18 19 20 |
# File 'lib/myrr/wallet.rb', line 18 def status @status end |
#stripe_customer_id ⇒ Object (readonly)
Returns the value of attribute stripe_customer_id.
18 19 20 |
# File 'lib/myrr/wallet.rb', line 18 def stripe_customer_id @stripe_customer_id end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
18 19 20 |
# File 'lib/myrr/wallet.rb', line 18 def updated_at @updated_at end |
Class Method Details
.create(agent_did:, metadata: {}, client: nil) ⇒ Myrr::Wallet
Create a new wallet for the given agent.
40 41 42 43 44 45 46 |
# File 'lib/myrr/wallet.rb', line 40 def self.create(agent_did:, metadata: {}, client: nil) client ||= Myrr.client body = { agent_did: agent_did } body[:metadata] = if .any? resp = client.send(:post, "/v1/wallets", body) new(resp) end |
.find(id, client: nil) ⇒ Myrr::Wallet?
Find a wallet by its UUID.
53 54 55 56 57 58 59 60 |
# File 'lib/myrr/wallet.rb', line 53 def self.find(id, client: nil) client ||= Myrr.client resp = client.send(:get, "/v1/wallets/#{id}") new(resp) rescue Myrr::Error => e raise unless e..include?("not_found") nil end |
.find_by_agent(agent_did, client: nil) ⇒ Myrr::Wallet?
Find a wallet by its agent did:myrr: identifier.
67 68 69 70 71 72 73 74 |
# File 'lib/myrr/wallet.rb', line 67 def self.find_by_agent(agent_did, client: nil) client ||= Myrr.client resp = client.send(:get, "/v1/wallets?agent_did=#{agent_did}") new(resp) rescue Myrr::Error => e raise unless e..include?("not_found") nil end |
Instance Method Details
#cards ⇒ Array<Myrr::Card>
List virtual cards for this wallet.
107 108 109 110 |
# File 'lib/myrr/wallet.rb', line 107 def cards resp = self.class.client.send(:get, "/v1/wallets/#{id}/cards") (resp["cards"] || []).map { |c| Myrr::Card.new(c) } end |
#fund(amount_cents:) ⇒ String
Create a Stripe Checkout session to fund this wallet.
99 100 101 102 |
# File 'lib/myrr/wallet.rb', line 99 def fund(amount_cents:) resp = self.class.client.send(:post, "/v1/wallets/#{id}/fund", { amount_cents: amount_cents }) resp["checkout_url"] end |
#topup(seller_did:, seller_name:, amount_cents:, payment_intent_id: nil, metadata: {}) ⇒ Hash
Pre-approve a Myrr Pay top-up before confirming the PaymentIntent.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/myrr/wallet.rb', line 84 def topup(seller_did:, seller_name:, amount_cents:, payment_intent_id: nil, metadata: {}) body = { seller_did: seller_did, seller_name: seller_name, amount_cents: amount_cents, payment_intent_id: payment_intent_id } body[:metadata] = if .any? self.class.client.send(:post, "/v1/wallets/#{id}/topups", body) end |
#transactions(limit: 20, before: nil) ⇒ Array<Myrr::Transaction>
List transactions for this wallet.
117 118 119 120 121 122 123 |
# File 'lib/myrr/wallet.rb', line 117 def transactions(limit: 20, before: nil) query = "limit=#{limit}" query += "&before=#{before}" if before resp = self.class.client.send(:get, "/v1/wallets/#{id}/transactions?#{query}") txns = (resp["transactions"] || []).map { |t| Myrr::Transaction.new(t) } [txns, resp["has_more"], resp["next_cursor"]] end |