Commit d5ecfdd5 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel

Payment requests are working

The fields aren't exactly as documented, though...
See https://together.bunq.com/d/13052-sandbox-api-how-to-get-money-onto-an-account/5
parent 30099072
......@@ -24,6 +24,8 @@ package bunqapi
import (
"fmt"
"github.com/sirupsen/logrus"
)
type wrappedMonetaryAccountBankResponse struct {
......@@ -69,6 +71,15 @@ type MonetaryAccountSetting struct {
RestrictionChat string `json:"restriction_chat"`
}
// AliasFields returns a log field for each alias of the account.
func (mab MonetaryAccountBank) AliasFields() logrus.Fields {
fields := logrus.Fields{}
for _, alias := range mab.Alias {
fields[alias.Type] = alias.Value
}
return fields
}
func (c *Client) GetMonetaryAccountBankList() []MonetaryAccountBank {
wrappedResponse := wrappedMonetaryAccountBankResponse{}
url := fmt.Sprintf("user/%d/monetary-account-bank", c.session.UserPerson.ID)
......
......@@ -22,6 +22,8 @@
package bunqapi
import "fmt"
// Amount describes a monetary amount.
type Amount struct {
// The amount formatted to two decimal places.
......@@ -29,3 +31,7 @@ type Amount struct {
// The currency of the amount. It is an ISO 4217 formatted currency code.
Currency string `json:"currency"`
}
func (amt Amount) String() string {
return fmt.Sprintf("%s %s", amt.Value, amt.Currency)
}
......@@ -63,17 +63,21 @@ func main() {
logrus.WithField("numAccounts", len(accounts)).Info("enough bank accounts found")
// Request some money
rfp := bunqapi.RequestInquiry{
AmountInquired: &bunqapi.Amount{Value: "300.00", Currency: "EUR"},
Description: "Daddy daddy can I play?",
AllowBunqme: true,
CounterpartyAlias: &bunqapi.LabelMonetaryAccount{
BunqMe: &bunqapi.Pointer{
Type: "EMAIL",
Value: "sugardaddy@bunq.com",
},
},
}
client.CreateRequestInquiry(accounts[0].ID, rfp)
// rfp := bunqapi.RequestInquiry{
// AmountInquired: &bunqapi.Amount{Value: "47.00", Currency: "EUR"},
// Description: "Daddy daddy can I play?",
// AllowBunqme: true,
// CounterpartyAlias: &bunqapi.LabelMonetaryAccount{
// Type: "EMAIL",
// Value: "sugardaddy@bunq.com",
// },
// }
// client.CreateRequestInquiry(accounts[1].ID, rfp)
for _, account := range accounts {
logrus.WithFields(account.AliasFields()).WithFields(logrus.Fields{
"accountID": account.ID,
"balance": account.Balance.String(),
}).Info("account balance")
}
}
......@@ -59,17 +59,21 @@ type RequestInquiry struct {
}
type LabelMonetaryAccount struct {
Type string `json:"type,omitempty"`
Value string `json:"value,omitempty"`
IBAN string `json:"iban,omitempty"`
DisplayName string `json:"display_name,omitempty"`
Avatar *Avatar `json:"avatar,omitempty"`
LabelUser *LabelUser `json:"label_user,omitempty"`
Country string `json:"country,omitempty"`
BunqMe *Pointer `json:"bunq_me,omitempty"`
IsLight bool `json:"is_light,omitempty"`
SwiftBic string `json:"swift_bic,omitempty"`
SwiftAccountNumber string `json:"swift_account_number,omitempty"`
TransferwiseAccountNumber string `json:"transferwise_account_number,omitempty"`
TransferwiseBankCode string `json:"transferwise_bank_code,omitempty"`
// BunqMe *Pointer `json:"bunq_me,omitempty"`
}
func (c *Client) CreateRequestInquiry(monetaryAccountID int, rfp RequestInquiry) int {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment