TrueLayer/Payment.pm

filter: Statementstmt 92.1% 35 / 38 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.0% 9 / 10 Podpod 100% 1 / 1 totaltotal 77.5% 45 / 58 CC 5 SCAR 24.3
CC
5
Cov
78%
hosted_payment_page_link
30.0
BEGIN
1.0
BEGIN
1.0
CRAP 11.4
↑ Summary TrueLayer/Request.pm »
1 package Business::TrueLayer::Payment;
2  
3 =head1 NAME
4  
5 Business::TrueLayer::Payment - class representing a payment
6 as used in the TrueLayer v3 API.
7  
8 Business::TrueLayer::Payment uses the Status role.
9  
10 =head1 SYNOPSIS
11  
12 my $Payment = Business::TrueLayer::Payment->new(
13 amount_in_minor => ...
14 );
15  
16 =cut
17  
18 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use feature qw/ signatures postderef /;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 extends 'Business::TrueLayer::Request';
24 2 with 'Business::TrueLayer::Role::Status';
25 2 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶no warnings qw/ experimental::signatures experimental::postderef /;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 2 with 'Business::TrueLayer::Types::User';
29 2 ▶use Business::TrueLayer::Payment::Method;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 =head1 ATTRIBUTES
34  
35 =over
36  
37 =item id (Str)
38  
39 =item resource_token (Str)
40  
41 =item amount_in_minor (Int)
42  
43 =item currency (Str)
44  
45 =item payment_method
46  
47 A L<Business::TrueLayer::Payment::Method> object. Hash refs will be coerced.
48  
49  
50 =item user
51  
52 A L<Business::TrueLayer::User> object. Hash refs will be coerced.
53  
54 =back
55  
56 =cut
57  
58 2 has [ qw/ status id resource_token metadata related_products / ] => (
59 is => 'ro',
60 isa => 'Str',
61 required => 0,
62 );
63  
64 2 has [ qw/ currency / ] => (
65 is => 'ro',
66 isa => 'Str',
67 required => 1,
68 );
69  
70 2 has [ qw/
71 amount_in_minor
72 / ] => (
73 is => 'ro',
74 isa => 'Int',
75 required => 1,
76 );
77  
78 coerce 'Business::TrueLayer::Payment::Method'
79 => from 'HashRef'
80 5 ▶ => via {
Subroutine __ANON__: called CC=1 SCAR=0.0
81 5 Business::TrueLayer::Payment::Method->new( %{ $_ } );
82 }
83 2 ;
84  
85 2 has payment_method => (
86 is => 'ro',
87 isa => 'Business::TrueLayer::Payment::Method',
88 coerce => 1,
89 required => 1,
90 );
91  
92 =head1 METHODS
93  
94 =head2 hosted_payment_page_link
95  
96 Returns the TrueLayer hosted payment page URI, allowing you to redirect
97 a user to it to complete the payment.
98  
99 my $link = $Payment->hosted_payment_page_link(
100 $return_uri, # must be one of those set in the TrueLayer console
101 );
102  
103 It only makes sense to do this after you have created a payment, so the
104 object will check some of its attributes and throw an exception if it is
105 not in the correct state.
106  
107 =cut
108  
109 0 ▶sub hosted_payment_page_link (
Subroutine hosted_payment_page_link: not called CC=5 SCAR=34.0
Pod documented
110 $self,
111 $return_uri = undef
112 0 ) {
113 0 ▶ ( $self->id && $self->resource_token )
Branch: 1 branch
BranchTrueFalseTotal
$self->id and $self->resource_token or confess("Payment lacks an id and resource_token") 0 0 0
Condition0%0/3
$self->id and $self->resource_token
!ll&&!rl&&r
000
MC/DC0%0/2
$self->id and $self->resource_token
$self->id $self->resource_token
Truth table0%0/3
A and B
A= $self->idB= $self->resource_token
ABresult
0X0
100
111
114 || confess( "Payment lacks an id and resource_token" );
115  
116 0 ▶ return 'https://' . $self->payment_host
Branch: 1 branch
BranchTrueFalseTotal
$return_uri ? : 0 0 0
117 . '/payments#'
118 . 'payment_id=' . $self->id
119 . '&resource_token=' . $self->resource_token
120 . ( $return_uri ? ( '&return_uri=' . $return_uri ) : '' )
121 }
122  
123 =head1 SEE ALSO
124  
125 L<Business::TrueLayer::Payment::Method>
126  
127 L<Business::TrueLayer::User>
128  
129 L<Business::TrueLayer::Role::Status>
130  
131 =cut
132  
133 2 1;
↑ Summary TrueLayer/Request.pm »