package II5117351e1a4f1d07d1c88690b7a75168::mod_google; use strict; use MIME::Base64; use LWP::UserAgent; use Data::Dumper; our $DebugMode = 0; sub checkPGateSettings { my $class = shift; my $settings = shift; my @errors; push @errors, 'check.empty_settings' unless $settings->{mid} && $settings->{key}; push @errors, 'check.https_off' if $ENV{HTTPS} ne 'on'; eval { local $SIG{__DIE__} = 'DEFAULT'; require Crypt::SSLeay; }; push @errors, ['check.no_mod', 'Crypt::SSLeay'] if $@; eval { local $SIG{__DIE__} = 'DEFAULT'; require Digest::HMAC_SHA1; }; push @errors, ['check.no_mod', 'Digest::HMAC_SHA1'] if $@; @errors; } sub checkProductSettings { my $class = shift; my ($product) = @_; my @errors; @errors; } sub go { my $class = shift; my $pgtxn = shift; my $currCode = $pgtxn->getCurrencyCode; my $xmlData; $xmlData = qq( <?xml version="1.0" encoding="UTF-8"?> <checkout-shopping-cart xmlns="http://checkout.google.com/schema/2"> <shopping-cart> <items>); if($pgtxn->{sale_id}) { my $sale = $pgtxn->getSale; $xmlData .= qq(<item> <item-name>$sale->{prod_title}</item-name> <item-description>$sale->{descr}</item-description> <unit-price currency="$currCode">$sale->{amount}</unit-price> <quantity>1</quantity> </item>); } else { for ($pgtxn->getOrderSalesList) { $xmlData .= qq(<item> <item-name>$_->{prod_title}</item-name> <item-description>$_->{descr}</item-description> <unit-price currency="$currCode">$_->{amount}</unit-price> <quantity>1</quantity> </item>); } } $xmlData .= qq( </items> <merchant-private-data>$pgtxn->{id}</merchant-private-data> </shopping-cart> </checkout-shopping-cart>); my $settings = $pgtxn->getPGateSettings; my $cart = compute_base64($xmlData); my $signature = compute_hmac_sha1($settings->{key}, $xmlData, 1); my $url = $DebugMode ? "https://sandbox.google.com/checkout/api/checkout/v2/checkout/Merchant/$settings->{mid}" : "https://checkout.google.com/api/checkout/v2/checkout/Merchant/$settings->{mid}"; my $form = { cart => $cart, signature => $signature, }; $pgtxn->logg('REQ', $xmlData); Zen->getRequest->redirectPOST($url, $form); } sub feedbackReturnPgt { my $class = shift; my $in = Zen->getRequest->getInput; my $httpAuth = $ENV{HTTP_AUTHORIZATION}; $httpAuth =~ s/Basic (\.*)/$1/; $httpAuth = decode_base64($httpAuth); my ($pgtxn, $txn_code); if($in->{_type} eq 'new-order-notification') { $pgtxn = II982446f8950cc3dc59e487adba22df54::IIlllIlIIllIIlll($II982446f8950cc3dc59e487adba22df54::lllllllIIlllIIIl{$IIb39071a48a82a07eeb9256f406abebc5::lIlIlIllIlllIIII},135,$II982446f8950cc3dc59e487adba22df54::lllllllIIlllIIIl{$II982446f8950cc3dc59e487adba22df54::llIlIIIIllllIIII})->get($in->{"shopping-cart.merchant-private-data"}); $pgtxn->logg('RET', $in); my $settings = $pgtxn->getPGateSettings; if($httpAuth ne "$settings->{mid}:$settings->{key}") { $pgtxn->logg('ERR', "Invalid username or password"); warn "ERR:Invalid username or password"; Jin::Assign->true(0,"Invalid username or password"); return; } $pgtxn->{txn_code} = $in->{"google-order-number"}; $pgtxn->save; } else { $txn_code = $in->{"google-order-number"}; $pgtxn = II8dae0e141ee45f5daba6a74e4a7c3b6f::lllIllIIIllIllII($IIb39071a48a82a07eeb9256f406abebc5::IlllIllIllIllIll{$II982446f8950cc3dc59e487adba22df54::lIIlIlIIIIIIllII},135,$IIb39071a48a82a07eeb9256f406abebc5::IlllIllIllIllIll{$II982446f8950cc3dc59e487adba22df54::IllIIIlIllllIlll})->search(txn_code => $txn_code)->[0]; $pgtxn->logg('RET', $in); my $settings = $pgtxn->getPGateSettings; if($httpAuth ne "$settings->{mid}:$settings->{key}") { $pgtxn->logg('ERR', "Invalid username or password."); warn "ERR:Invalid username or password"; Jin::Assign->true(0,"Invalid username or password"); return; } } if($in->{_type} eq 'charge-amount-notification') { $pgtxn->txnPayment($txn_code); } elsif($in->{_type} eq 'refund-amount-notification') { $pgtxn->txnRefund; } elsif($in->{_type} eq 'order-state-change-notification') { $pgtxn->txnPayment($txn_code) if $in->{"new-financial-order-state"} eq 'CANCELLED'; } Zen->getRequest->printHeader('text/xml'); $pgtxn->logg('REQ', '200 OK'); return; } sub compute_hmac_sha1 { my ($key, $data, $b64) = @_; require Digest::HMAC_SHA1; my $hmac = Digest::HMAC_SHA1->new($key); $hmac->add($data); my $secure = $b64 ? $hmac->b64digest : $hmac->digest; while (length($secure) % 4) { $secure .= '='; } return $secure; } sub compute_base64 { my ($data) = @_; return encode_base64($data, ""); } 1; 