| 1 | package Web::MarketReceipt::Verifier::Mock::AppStore; | ||||||||||
| 2 | 1 | ▶ | use Mouse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | extends 'Web::MarketReceipt::Verifier'; | |||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use Web::MarketReceipt; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use MIME::Base64 qw/decode_base64/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | has verifier => ( | ||||||||||
| 11 | is => 'ro', | ||||||||||
| 12 | isa => 'CodeRef', | ||||||||||
| 13 | default => sub { | ||||||||||
| 14 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 1 | ▶ | return sub { $self->_default_verifier(@_) }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 17 | }, | ||||||||||
| 18 | 1 | lazy => 1, | |||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 1 | ▶ | no Mouse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | sub _default_verifier { | ||||||||||
| 24 | 1 | ▶ | my ($self, %args) = @_; | ||||||||
|
Subroutine
_default_verifier: called CC=2 SCAR=6.9
| |||||||||||
| 25 | |||||||||||
| 26 | 1 | my $receipt = $args{receipt}; | |||||||||
| 27 | |||||||||||
| 28 | 1 | my $parsed = $self->_parse_receipt($receipt); | |||||||||
| 29 | |||||||||||
| 30 | 1 | my $purchase_info = $parsed->{'purchase-info'}; | |||||||||
| 31 | my %underscored = ( | ||||||||||
| 32 | map { | ||||||||||
| 33 | 1 | my $key = $_; | |||||||||
| 34 | 14 | $key =~ s/-/_/g; | |||||||||
| 35 | 14 | $key => $purchase_info->{$_} | |||||||||
| 36 | } keys %$purchase_info | ||||||||||
| 37 | ); | ||||||||||
| 38 | my $environment = exists $parsed->{environment} ? | ||||||||||
| 39 | 1 | ▶ | $parsed->{environment} : 'Production'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | my $result = Web::MarketReceipt->new( | ||||||||||
| 42 | is_success => 1, | ||||||||||
| 43 | store => 'AppStore', | ||||||||||
| 44 | raw => \%underscored, | ||||||||||
| 45 | orders => [ | ||||||||||
| 46 | { | ||||||||||
| 47 | product_identifier => $underscored{product_id}, | ||||||||||
| 48 | unique_identifier => 'AppStore:' . $underscored{original_transaction_id}, | ||||||||||
| 49 | purchased_epoch => $underscored{original_purchase_date_ms}, | ||||||||||
| 50 | quantity => $underscored{quantity}, | ||||||||||
| 51 | 1 | environment => $environment, | |||||||||
| 52 | state => 'purchased', | ||||||||||
| 53 | } | ||||||||||
| 54 | ], | ||||||||||
| 55 | ); | ||||||||||
| 56 | |||||||||||
| 57 | 1 | return $result; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | sub verify { | ||||||||||
| 61 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
verify: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 62 | |||||||||||
| 63 | 1 | return $self->verifier->(@_); | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | sub _parse_receipt { | ||||||||||
| 67 | 1 | ▶ | my ($class, $receipt) = @_; | ||||||||
|
Subroutine
_parse_receipt: called CC=1 SCAR=0.0
| |||||||||||
| 68 | |||||||||||
| 69 | 1 | my $data = $class->_parse_oldstlye_plist($receipt); | |||||||||
| 70 | 1 | my $purchase_info = $class->_parse_oldstlye_plist($data->{'purchase-info'}); | |||||||||
| 71 | 1 | $data->{'purchase-info'} = $purchase_info; | |||||||||
| 72 | |||||||||||
| 73 | 1 | return $data; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | # XXX: This parser is poor but I look work with a receipt from appstore. | ||||||||||
| 77 | # If that do not parse at your receipt, please report issues or pull requests. | ||||||||||
| 78 | sub _parse_oldstlye_plist { | ||||||||||
| 79 | 2 | ▶ | my ($class, $text) = @_; | ||||||||
|
Subroutine
_parse_oldstlye_plist: called CC=1 SCAR=0.0
| |||||||||||
| 80 | |||||||||||
| 81 | 2 | my $data = decode_base64($text); | |||||||||
| 82 | 2 | my ($properties_str) = $data =~ /{(.*)}/s; | |||||||||
| 83 | 2 | my %kv = $properties_str =~ /\s*"(.*?)"\s*=\s*"(.*?)"\s*;/msg; | |||||||||
| 84 | |||||||||||
| 85 | 2 | return \%kv; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 1 | 1; | |||||||||
| 89 | |||||||||||
| 90 | __END__ | ||||||||||