blib/lib/Web/MarketReceipt/Verifier/GooglePlay.pm

filter: Statementstmt 90.3% 47 / 52 Branchbran 31.2% 5 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 1 totaltotal 79.5% 66 / 83 SCAR 23.1
CC
9
Cov
76%
_purchase_state
22.9
verify
4.0
BEGIN
1.0
CRAP 10.1
« blib/lib/Web/MarketReceipt/Verifier/AppStore.pm ↑ Summary blib/lib/Web/MarketReceipt.pm »
1 package Web::MarketReceipt::Verifier::GooglePlay;
2 2 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Mouse::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 extends 'Web::MarketReceipt::Verifier';
5 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Web::MarketReceipt;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Crypt::OpenSSL::RSA;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶subtype 'Crypt::OpenSSL::RSA' => as 'Object' => where { $_->isa('Crypt::OpenSSL::RSA') };
Subroutine __ANON__: called CC=1 SCAR=0.0
14 coerce 'Crypt::OpenSSL::RSA'
15 => from 'Str',
16 2 ▶ => via { Crypt::OpenSSL::RSA->new_public_key($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
17  
18 # need pem format
19 2 has public_key => (
20 is => 'ro',
21 isa => 'Crypt::OpenSSL::RSA',
22 required => 1,
23 coerce => 1,
24 );
25  
26 2 ▶no Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 sub verify {
29 2 ▶ my ($self, %args) = @_;
Subroutine verify: called CC=4 SCAR=14.0
Pod undocumented
30  
31 # TODO 例外処理
32 2 my $signed_data = decode_base64 $args{signed_data};
33 2 my $signature = decode_base64 $args{signature};
34  
35 2 my $verification_result = $self->public_key->verify($signed_data, $signature);
36 2 my $raw_json = decode_json $signed_data;
37  
38 Web::MarketReceipt->new(
39 is_success => $verification_result ? 1 : 0,
40 store => 'GooglePlay',
41 raw => $raw_json,
42 $verification_result ? (
43 exists $raw_json->{orders} ? (
44 2 ▶ orders => [ map { $self->_order2hash($_) } @{ $raw_json->{orders} } ],
Branch: 3 branches
BranchTrueFalseTotal
$verification_result ? : 2 0 2
$verification_result ? : 2 0 2
exists $raw_json->{'orders'} ? : 1 1 2
45 ) : (
46 orders => [ $self->_order2hash($raw_json) ],
47 ),
48 ) : (),
49 );
50 }
51  
52 sub _order2hash {
53 2 ▶ my ($self, $order) = @_;
Subroutine _order2hash: called CC=1 SCAR=0.0
54  
55 return {
56 product_identifier => $order->{productId},
57 unique_identifier => 'GooglePlay:' . $order->{orderId},
58 purchased_epoch => int( $order->{purchaseTime}/1000 ),
59 2 state => $self->_purchase_state($order->{purchaseState}),
60 quantity => 1,
61 environment => 'Production',
62 };
63 }
64  
65 sub _purchase_state {
66 2 ▶ my ($self, $purchase_state) = @_;
Subroutine _purchase_state: called CC=6 SCAR=31.3
67  
68 2 ▶ if ($purchase_state == 0) {
Branch: 5 branches
BranchTrueFalseTotal
if ($purchase_state == 0) { } 2 0 2
elsif ($purchase_state == 1) { } 0 0 0
elsif ($purchase_state == 2) { } 0 0 0
elsif ($purchase_state == 3) { } 0 0 0
elsif ($purchase_state == 4) { } 0 0 0
69 2 return 'purchased';
70 } elsif ($purchase_state == 1) {
71 0 return 'canceled';
72 } elsif ($purchase_state == 2) {
73 0 return 'refunded';
74 } elsif ($purchase_state == 3) {
75 0 return 'expired';
76 } elsif ($purchase_state == 4) {
77 0 return 'pending';
78 }
79  
80 0 croak sprintf 'invalid purchase state: %s', $purchase_state;
81 }
82  
83 2 1;
« blib/lib/Web/MarketReceipt/Verifier/AppStore.pm ↑ Summary blib/lib/Web/MarketReceipt.pm »