Permalink
Browse files

resolve #2 - add ->attachements attr to Transaction

coerced from an arrayref of hashes into an arrayref of Attachment
objects. update/add tests to reflect changes and correct spelling
of attachment in some places (spurious letter e, this is english
not french)
  • Loading branch information...
1 parent e3d3063 commit c29377f37d9ca8443e7bd74ae7af9efee61b5ec7 @leejo committed Apr 30, 2016
Showing with 76 additions and 6 deletions.
  1. +1 −1 README.md
  2. +3 −2 lib/Business/Mondo.pm
  3. +23 −0 lib/Business/Mondo/Transaction.pm
  4. +14 −1 mondo_emulator.pl
  5. +6 −1 t/002_end_to_end.t
  6. +1 −1 t/004_end_to_end_LIVE.t
  7. +28 −0 t/business/mondo/transaction.t
View
@@ -75,7 +75,7 @@ will, for the most part, return new instances of objects.
$Webhook->delete
}
- # attachements
+ # attachments
my $Attachment = $mondo->upload_attachment(
file_name => 'foo.png',
file_type => 'image/png',
@@ -75,7 +75,7 @@ will, for the most part, return new instances of objects.
$Webhook->delete
}
- # attachements
+ # attachments
my $Attachment = $mondo->upload_attachment(
file_name => 'foo.png',
file_type => 'image/png',
@@ -172,7 +172,8 @@ has client => (
default => sub {
my ( $self ) = @_;
- return Business::Mondo::Client->new(
+ # fix any load order issues with Resources requiring a Client
+ $Business::Mondo::Resource::client = Business::Mondo::Client->new(
token => $self->token,
api_url => $self->api_url,
);
@@ -17,6 +17,7 @@ with 'Business::Mondo::Currency';
use Types::Standard qw/ :all /;
use Business::Mondo::Merchant;
+use Business::Mondo::Attachment;
use DateTime::Format::DateParse;
=head1 ATTRIBUTES
@@ -34,6 +35,7 @@ The Transaction class has the following attributes (with their type).
currency (Data::Currency)
created (DateTime)
settled (DateTime)
+ attachments (ArrayRef[Business::Mondo::Attachment])
Note that if a HashRef or Str is passed to ->merchant it will be coerced
into a Business::Mondo::Merchant object. When a Str is passed to ->currency
@@ -87,6 +89,27 @@ has merchant => (
},
);
+has attachments => (
+ is => 'ro',
+ isa => Maybe[ArrayRef[InstanceOf['Business::Mondo::Attachment']]],
+ coerce => sub {
+ my ( $args ) = @_;
+
+ return undef if ! defined $args;
+
+ my @attachments;
+
+ foreach my $attachment ( @{ $args } ) {
+ push( @attachments,Business::Mondo::Attachment->new(
+ client => $Business::Mondo::Resource::client,
+ %{ $attachment },
+ ) );
+ }
+
+ return [ @attachments ];
+ },
+);
+
has [ qw/ created settled / ] => (
is => 'ro',
isa => Maybe[InstanceOf['DateTime']],
View
@@ -250,6 +250,17 @@ sub _transactions {
more_stuff => 'yep',
};
+ my $attachment = {
+ "created" => "2016-04-23T12:46:41Z",
+ "external_id" => "tx_0000...",
+ "file_type" => "image/jpeg",
+ "file_url" => "https://...",
+ "id" => "attach_0000...",
+ "type" => "image/jpeg",
+ "url" => "https://...",
+ "user_id" => "user_0000..."
+ };
+
return [
{
"account_balance" => 13013,
@@ -265,6 +276,7 @@ sub _transactions {
"notes" => "Salmon sandwich 🍞",
"is_load" => Mojo::JSON::false,
"settled" => '2015-08-23T12:20:18Z',
+ "attachments" => [ $attachment,$attachment ],
},
{
"account_balance" => 12334,
@@ -280,7 +292,8 @@ sub _transactions {
"notes" => "",
"is_load" => Mojo::JSON::false,
"settled" => '2015-08-23T12:20:18Z',
- "category" => "eating_out"
+ "category" => "eating_out",
+ "attachments" => [ $attachment,$attachment ],
},
];
}
View
@@ -48,6 +48,11 @@ isa_ok(
);
isa_ok(
+ $Transaction->attachments->[1],
+ 'Business::Mondo::Attachment',
+);
+
+isa_ok(
$Transaction->annotate( foo => 'bar' ),
'Business::Mondo::Transaction',
);
@@ -98,7 +103,7 @@ is( $Balance->balance,5000,'->balance' );
isa_ok( $Balance->currency,'Data::Currency','->currency' );
is( $Balance->spend_today,0,'->spend_today' );
-note( "Attachement" );
+note( "Attachment" );
isa_ok( my $Attachment = $Mondo->upload_attachment(
file_name => 'foo.png',
file_type => 'image/png',
@@ -110,7 +110,7 @@ ok( $Balance->balance,'->balance' );
isa_ok( $Balance->currency,'Data::Currency','->currency' );
is( $Balance->spend_today,0,'->spend_today' );
-note( "Attachement" );
+note( "Attachment" );
isa_ok( my $Attachment = $Mondo->upload_attachment(
file_name => 'foo.png',
file_type => 'image/png',
@@ -40,6 +40,7 @@ can_ok(
merchant
currency
created
+ attachments
/,
);
@@ -63,6 +64,11 @@ cmp_deeply(
'->annotations'
);
+isa_ok(
+ $Transaction->attachments->[1],
+ 'Business::Mondo::Attachment',
+);
+
ok( $Transaction->to_hash,'to_hash' );
ok( $Transaction->as_json,'to_json' );
ok( $Transaction->TO_JSON,'TO_JSON' );
@@ -104,6 +110,28 @@ sub _transaction {
"name" => "The De Beauvoir Deli Co.",
"category" => "eating_out"
},
+ "attachments" => [
+ {
+ "created" => "2016-04-23T12:46:41Z",
+ "external_id" => "tx_0000...",
+ "file_type" => "image/jpeg",
+ "file_url" => "https://...",
+ "id" => "attach_0000...",
+ "type" => "image/jpeg",
+ "url" => "https://...",
+ "user_id" => "user_0000..."
+ },
+ {
+ "created" => "2016-04-23T12:46:41Z",
+ "external_id" => "tx_0000...",
+ "file_type" => "image/jpeg",
+ "file_url" => "https://...",
+ "id" => "attach_0000...",
+ "type" => "image/jpeg",
+ "url" => "https://...",
+ "user_id" => "user_0000..."
+ },
+ ],
"metadata" => $metadata // {},
"notes" => "Salmon sandwich 🍞",
"is_load" => Cpanel::JSON::XS::false,

0 comments on commit c29377f

Please sign in to comment.