has
[
qw/
id account_id category dedupe_id description notes scheme
/
] => (
is
=>
'ro'
,
isa
=> Str,
);
has
[
qw/ account_balance amount local_amount /
] => (
is
=>
'ro'
,
isa
=> Int,
);
has
[
qw/ counterparty metadata /
] => (
is
=>
'ro'
,
isa
=> HashRef,
);
has
[
qw/ is_load originator /
] => (
is
=>
'ro'
,
isa
=> Any,
);
has
merchant
=> (
is
=>
'ro'
,
isa
=> Maybe[InstanceOf[
'Business::Monzo::Merchant'
]],
coerce
=>
sub
{
my
(
$args
) =
@_
;
return
undef
if
!
defined
$args
;
if
(
ref
(
$args
) eq
'HASH'
) {
return
undef
if
!
keys
%{
$args
};
$args
= Business::Monzo::Merchant->new(
client
=>
$Business::Monzo::Resource::client
,
%{
$args
},
);
}
elsif
( !
ref
(
$args
) ) {
$args
= Business::Monzo::Merchant->new(
client
=>
$Business::Monzo::Resource::client
,
id
=>
$args
,
);
}
return
$args
;
},
);
has
attachments
=> (
is
=>
'ro'
,
isa
=> Maybe[ArrayRef[InstanceOf[
'Business::Monzo::Attachment'
]]],
coerce
=>
sub
{
my
(
$args
) =
@_
;
return
undef
if
!
defined
$args
;
my
@attachments
;
foreach
my
$attachment
( @{
$args
} ) {
push
(
@attachments
,Business::Monzo::Attachment->new(
client
=>
$Business::Monzo::Resource::client
,
%{
$attachment
},
) );
}
return
[
@attachments
];
},
);
has
[
qw/ created updated settled /
] => (
is
=>
'ro'
,
isa
=> Maybe[InstanceOf[
'DateTime'
]],
coerce
=>
sub
{
my
(
$args
) =
@_
;
if
( !
ref
(
$args
) ) {
$args
= DateTime::Format::DateParse->parse_datetime(
$args
);
}
return
$args
;
},
);
sub
get {
shift
->SUPER::get(
'transaction'
);
}
sub
annotate {
my
(
$self
,
%annotations
) =
@_
;
%annotations
=
$self
->_params_as_array_string(
'metadata'
,\
%annotations
);
my
$data
=
$self
->client->api_patch(
$self
->url,\
%annotations
);
$data
=
$data
->{transaction};
return
$self
->new(
client
=>
$self
->client,
%{
$data
},
);
}
sub
annotations {
return
shift
->metadata;
}
sub
BUILD {
my
(
$self
,
$args
) =
@_
;
foreach
my
$c
(
'local_'
,
''
) {
my
$amount_accessor
=
"${c}amount"
;
my
$currency_accessor
=
"${c}currency"
;
if
(
my
$amount
=
$self
->
$amount_accessor
) {
my
$decimal_precision
= decimal_precision(
$self
->
$currency_accessor
->code ) // 0;
my
$value
=
$amount
/ ( 10 **
$decimal_precision
);
$self
->
$currency_accessor
->value(
$value
);
}
}
};
1;