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

Added user/{user-id}/monetary-account/{account-id}/payment/{payment-id}

parent 76786482
......@@ -37,7 +37,7 @@ type wrappedIDResponse struct {
Response []idResponse `json:"Response"`
}
type idResponse struct {
ID BunqID `json:"Id"`
ID *BunqID `json:"Id,omitempty"`
}
// Geolocation is defined by the bunq API.
......
......@@ -111,8 +111,9 @@ func (c *Client) GetMonetaryAccountBankList() []MonetaryAccountBank {
return accounts
}
// GetMonetaryAccountBank returns a single bank account.
func (c *Client) GetMonetaryAccountBank(accountID int) (MonetaryAccountBank, error) {
logger := logrus.WithField("accountID", accountID)
logger := log.WithField("accountID", accountID)
wrappedResponse := wrappedMonetaryAccountBankResponse{}
url := fmt.Sprintf("user/%d/monetary-account-bank/%d", c.session.UserPerson.ID, accountID)
......
......@@ -22,7 +22,12 @@
package bunqapi
import "fmt"
import (
"errors"
"fmt"
"github.com/sirupsen/logrus"
)
// Payment is defined by the bunq API.
type Payment struct {
......@@ -55,6 +60,10 @@ type Payment struct {
// request_reference_split_the_bill
}
type wrappedPaymentResponse struct {
Response []Payment `json:"Response"`
}
// CreatePayment performs a payment.
func (c *Client) CreatePayment(fromMonetaryAccountID int, payment Payment) int {
wrappedResponse := wrappedIDResponse{}
......@@ -70,3 +79,23 @@ func (c *Client) CreatePayment(fromMonetaryAccountID int, payment Payment) int {
log.WithField("paymentID", response.ID.ID).Info("payment performed")
return response.ID.ID
}
// GetPayment returns info about a payment.
func (c *Client) GetPayment(accountID, paymentID int) (Payment, error) {
logger := log.WithFields(logrus.Fields{
"accountID": accountID,
"paymentID": paymentID,
})
wrappedResponse := wrappedPaymentResponse{}
url := fmt.Sprintf("user/%d/monetary-account/%d/payment/%d", c.session.UserPerson.ID, accountID, paymentID)
errResp := c.DoRequest("GET", url, nil, &wrappedResponse)
if errResp != nil {
logger.WithFields(errResp.LogFields()).Error("error requesting payment")
return Payment{}, errors.New("error requesting payment")
}
payment := Payment{}
MergeStructs(wrappedResponse.Response, &payment)
return payment, nil
}
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