| 1 | package VendorAPI::2Checkout::Client::Moose; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use MooseX::NonMoose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | extends 'VendorAPI::2Checkout::Client'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Params::Validate qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | our $VERSION = '0.1502'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub _base_uri { 'https://www.2checkout.com/api' }; | ||||||||||||||||||||||||||
|
Subroutine
_base_uri: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub _realm { '2CO API' }; | ||||||||||||||||||||||||||
|
Subroutine
_realm: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub _netloc { 'www.2checkout.com:443' }; | ||||||||||||||||||||||||||
|
Subroutine
_netloc: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | enum 'Format' => qw( XML JSON ); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | class_type 'LPW::UserAGent'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | has ua => ( | |||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||
| 25 | isa => 'LWP::UserAgent', | ||||||||||||||||||||||||||||
| 26 | lazy => 1, | ||||||||||||||||||||||||||||
| 27 | builder => '_buld_ua', | ||||||||||||||||||||||||||||
| 28 | init_arg => undef, | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | has accept => ( | |||||||||||||||||||||||||||
| 32 | isa => 'Str', | ||||||||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||||||||
| 34 | builder => '_build_accept', | ||||||||||||||||||||||||||||
| 35 | required => 1, | ||||||||||||||||||||||||||||
| 36 | init_arg => 'format', | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub _build_accept { mime_type($_[1]); } | ||||||||||||||||||||||||||
|
Subroutine
_build_accept: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | has [ qw(username password) ] => ( | |||||||||||||||||||||||||||
| 42 | isa => 'Str', | ||||||||||||||||||||||||||||
| 43 | is => 'ro', | ||||||||||||||||||||||||||||
| 44 | required => 1, | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub _buld_ua { | ||||||||||||||||||||||||||
|
Subroutine
_buld_ua: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 48 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 49 | 0 | my $ua = LWP::UserAgent->new( agent => "VendorAPI::2Checkout::Client/${VERSION} " ); | |||||||||||||||||||||||||||
| 50 | 0 | $ua->credentials(_netloc(), _realm(), $self->username, $self->password); | |||||||||||||||||||||||||||
| 51 | 0 | return $ua; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 4 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 4 | my $class = shift; | |||||||||||||||||||||||||||
| 56 | 4 | return { username => $_[0], password => $_[1], format => $class->mime_type($_[2]), }; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =item $response = $c->list_sales(); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Retrieves the list of sales for the vendor | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | my $sort_col_re = qr/^(sale_id|date_placed|customer_name|recurring|recurring_declined|usd_total)$/; | |||||||||||||||||||||||||||
| 67 | 1 | my $sort_dir_re = qr/^(ASC|DESC)$/; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | my %v = ( | |||||||||||||||||||||||||||
| 70 | sale_id => { type => SCALAR, regex => qw/^\d+$/ , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 71 | invoice_id => { type => SCALAR, regex => qw/^\d+$/ , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 72 | pagesize => { type => SCALAR, regex => qw/^\d+$/ , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 73 | cur_page => { type => SCALAR, regex => qw/^\d+$/ , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 74 | customer_name => { type => SCALAR, regex => qw/^[-A-Za-z.]+$/ , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 75 | customer_email => { type => SCALAR, regex => qw/^[-\w.+@]+$/ , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 76 | customer_phone => { type => SCALAR, regex => qw/^[\d()-]+$/ , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 77 | vendor_product_id => { type => SCALAR, regex => qw/^.+$/ , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 78 | ccard_first6 => { type => SCALAR, regex => qw/^\d{6}$/ , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 79 | ccard_last2 => { type => SCALAR, regex => qw/^\d\d$/ , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 80 | date_sale_end => { type => SCALAR, regex => qw/^\d{4}-\d\d-\d\d$/ , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 81 | date_sale_begin => { type => SCALAR, regex => qw/^\d{4}-\d\d-\d\d$/ , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 82 | sort_col => { type => SCALAR, regex => $sort_col_re , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 83 | sort_dir => { type => SCALAR, regex => $sort_dir_re , untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 84 | active_recurrings => { type => SCALAR, regex => qr/^[01]$/, untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 85 | declined_recurrings => { type => SCALAR, regex => qr/^[01]$/, untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 86 | refunded => { type => SCALAR, regex => qr/^[01]$/, untaint => 1, optional => 1, }, | ||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | my $_profile = { map { $_ => $v{$_} } keys %v }; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub list_sales { | ||||||||||||||||||||||||||
|
Subroutine
list_sales: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 94 | 0 | my $path = '/sales/list_sales'; | |||||||||||||||||||||||||||
| 95 | 0 | my %input_params = validate(@_, $_profile); | |||||||||||||||||||||||||||
| 96 | 0 | $self->call_2co_api($path, \%input_params); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =item $response = $c->detail_sale(sale_id => $sale_id); | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Retrieves the details for the named sale. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub detail_sale { | ||||||||||||||||||||||||||
|
Subroutine
detail_sale: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 108 | 0 | my $_detail_profile = { map { $_ => $v{$_} } qw/sale_id invoice_id/ }; | |||||||||||||||||||||||||||
| 109 | 0 | my %p = validate(@_, $_detail_profile); | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | unless ($p{sale_id} || $p{invoice_id}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p{"sale_id"} or $p{"invoice_id"}
MC/DC0%0/2
$p{"sale_id"} or $p{"invoice_id"}
$p{"sale_id"}
$p{"invoice_id"}
Truth table0%0/3
A or B
A= $p{"sale_id"}B= $p{"invoice_id"}
| |||||||||||||||||||||||||||||
| 112 | 0 | confess("detail_sale requires sale_id or invoice_id and received neither"); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | my $path = '/sales/detail_sale'; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | my %params; | |||||||||||||||||||||||||||
| 118 | 0 | ▶ | if ($p{invoice_id} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | $params{invoice_id} = $p{invoice_id}; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | else { | ||||||||||||||||||||||||||||
| 122 | 0 | $params{sale_id} = $p{sale_id}; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | $self->call_2co_api($path, \%params); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =item $response = $c->list_coupons(); | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | Retrieves the list of coupons for the vendor | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub list_coupons { | ||||||||||||||||||||||||||
|
Subroutine
list_coupons: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 135 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 136 | 0 | $self->call_2co_api('/products/list_coupons'); | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =item $response = $c->detail_coupon(coupon_code => $coupon_code); | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | Retrieves the details for the named coupon. | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub detail_coupon { | ||||||||||||||||||||||||||
|
Subroutine
detail_coupon: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 146 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 147 | 0 | my $_detail_profile = { coupon_code => { type => SCALAR, regex => qr/^\w+$/, untaint => 1, optional => 0, }, }; | |||||||||||||||||||||||||||
| 148 | 0 | my %p = validate(@_, $_detail_profile); | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | unless ( $p{coupon_code} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | confess("detail_coupon requires coupon_code"); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | my $path = '/products/detail_coupon'; | |||||||||||||||||||||||||||
| 155 | 0 | my %params = (coupon_code => $p{coupon_code} ); | |||||||||||||||||||||||||||
| 156 | 0 | $self->call_2co_api($path, \%params); | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =item $response = $c->list_payments(); | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Retrieves the list of payments for the vendor | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =cut | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub list_payments { | ||||||||||||||||||||||||||
|
Subroutine
list_payments: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 166 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 167 | 0 | $self->call_2co_api('/acct/list_payments'); | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =item $response = $c->list_products(); | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | Retrieves the list of products for the vendor | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =cut | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub list_products { | ||||||||||||||||||||||||||
|
Subroutine
list_products: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 178 | 0 | $self->call_2co_api('/products/list_products'); | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =item $response = $c->list_options(); | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | Retrieves the list of options for the vendor | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =cut | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | sub list_options { | ||||||||||||||||||||||||||
|
Subroutine
list_options: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 189 | 0 | $self->call_2co_api('/products/list_options'); | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =item $response = $c->call_2co_api(); | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | Talks to 2CO on behalf of the API methods | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =cut | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | sub call_2co_api { | ||||||||||||||||||||||||||
|
Subroutine
call_2co_api: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 199 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 200 | 0 | my $api_path = shift; | |||||||||||||||||||||||||||
| 201 | 0 | my $query_params = shift; | |||||||||||||||||||||||||||
| 202 | 0 | ▶ | return undef unless $api_path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | my $uri = URI->new(_base_uri() . $api_path); | |||||||||||||||||||||||||||
| 204 | 0 | my %headers = ( Accept => $self->accept() ); | |||||||||||||||||||||||||||
| 205 | 0 | for my $k ( keys %$query_params ) { | |||||||||||||||||||||||||||
| 206 | 0 | $uri->query_param($k => $query_params->{$k}); | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | 0 | $self->ua->get($uri, %headers); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 212 | 1 | 1; | |||||||||||||||||||||||||||