// check that receiver_email is your Primary PayPal email // check that payment_amount/payment_currency are correct // process payment fputs($log, "\n" . 'Paypal says "VERIFIED"'); if ($receiver_email != $API_UserName) { fputs($log, "\nReceiver_email CONFIRMED"); } else { fputs($log, "\nReceiver_email WRONG!!!"); } switch ($txn_type) { case 'cart': if ($txn_id) { $cart = $mxdb->getcartbytransaction($txn_id); fputs($log, "\ncart id=" . $cart->id); if ($payment_status == "Completed" && $cart->paymentstatus != 'Completed') { mx_confirmcart($cart->accountid, $cart->id); } } break; case 'recurring_payment_profile_created': // cool, nothing to do for now... mx_setsubrenewal($recurring_payment_id, $next_payment_date); fputs($log, "\nrecurring payment ID:" . $recurring_payment_id); break; case 'recurring_payment_profile_cancel': mx_norenewsub($recurring_payment_id); fputs($log, "\nrecurring payment ID:" . $recurring_payment_id); break; case 'recurring_payment': if ($payment_status == 'Completed') { mx_confirmsubrenewal($recurring_payment_id, $next_payment_date);
function mx_ckcart($page, $option, $action) { global $mxuser, $prodtypes, $subtypes, $prodprice; $cartid = mx_secureword($_REQUEST['cartid']); $token = mx_securestring($_GET['token']); $cart = $mxuser->getcart($cartid ? $cartid : null, $action == 'printorder' || $action == 'confckout'); // get informed cart, pending cart or open new one if ($token && $action == '') { $action = 'ppcall'; } //if ($action=='pp-checkout' || $action=='confckout') { $cart->lines = $mxuser->getcartdetails($cart->id); $cart->total = 0; foreach ($cart->lines as $line) { //if ($line->prodtype!=MXARTSUB || $line->prodvar!=MXSUBFOY) $cart->total += $line->price; if ($line->prodtype == MXARTSUB) { $user = $mxuser->getuserinfo($line->prodref); $line->name = htmlentities(substr(mx_getartistname($user), 0, 80)); } else { if ($line->prodtype == MXSITESUB) { $line->name = sprintf('Account #%d', $mxuser->id); } else { if ($line->prodtype == MXMEDSUB) { $media = $mxuser->getmediainfo($line->prodref); $line->name = htmlentities(substr($media->title, 0, 80)); } else { $line->name = _('Unnamed Product'); } } } $line->desc = $prodtypes[$line->prodtype][0] . ', ' . $prodtypes[$line->prodtype][1][$line->prodvar]; } switch ($cart->taxcountrycode) { // Add for CANADIAN TAXES /* case 'CA': $cart->taxes=$cart->total*MXTAXHST; break; */ default: $cart->taxes = 0; break; } $cart->items = count($cart->lines); //} switch ($action) { // adding to cart case 'addfoy': case 'addfofa': case 'upgfofa': $subnum = 0; $artistid = mx_secureword($_REQUEST['id']); $prodvar = $action == 'addfoy' ? MXSUBFOY : ($action == 'addfofa' ? MXSUBFOFA : MXUPGFOFA); $price = $action == 'addfoy' ? MXFEEFOY : ($action == 'addfofa' ? MXFEEFOFA : MXFEEFOFA - MXFEEFOY); foreach ($cart->lines as $line) { $subnum += $line->prodtype == MXARTSUB && $line->prodref != $artistid ? 1 : 0; } if ($subnum < 10) { $mxuser->addcart($cart->id, MXARTSUB, $artistid, $prodvar, $price); $prodprice = $price; } else { $cart->err = array('sorry' => _('We\'re sorry but our payment processing' . ' company<br/>limits the number of yearly fanships per order to 10.<br/>' . ' In case you would like to become a fan of more than 10 artists,<br/>' . ' please do it in separate orders. Thank you.')); } //$mxuser->addwish(MXARTSUB,$artistid,$prodvar,$price); $cart->progress = 1; break; //case 'freesub': //case 'freesub': case 'basicsub': case 'plussub': case 'premsub': $subnum = 0; $prodref = -1; // site wide (no ref) $prodvar = $subtypes[$action]; // site subscription type if ($action == 'freesub') { $price = MXFEEFREE; } else { if ($action == 'basicsub') { $price = MXFEEBASIC; } else { if ($action == 'plussub') { $price = MXFEEPLUS; } else { if ($action == 'premsub') { $price = MXFEEPREMIUM; } } } } foreach ($cart->lines as $line) { $subnum += $line->prodtype != MXSITESUB ? 1 : 0; } if ($subnum < 10) { $mxuser->addcart($cart->id, MXSITESUB, $prodref, $prodvar, $price); $prodprice = $price; } else { $cart->err = array('sorry' => _('We\'re sorry but our payment processing' . ' company<br/>limits the number of subscriptions per order to 10.<br/>' . ' In case you would like to make more than 10 subscriptions,<br/>' . ' please do so in separate orders. Thank you.')); } //$mxuser->addwish(MXSITESUB,$artistid,$prodvar,$price); $cart->progress = 1; break; case 'medbuy': $prodref = preg_replace('%[^0-9]%', '', mx_secureword($_REQUEST['m'])); $media = $mxuser->getmediainfo($prodref); if ($media->type == MXMEDIABASEBUNDLE || $media->type == MXMEDIAREGULARBUNDLE) { $price = $media->cartprice; //round(MXFEESONGS*($media->tracks+($media->bigpics>4?($media->bigpics-4):0)+$media->videos),2); $prodvar = MXBUYBUNDLE; } else { if ($media->type == MXMEDIAINSTR || ($media->type = MXMEDIASONG)) { $price = $media->cartprice; //MXFEE1SONG; $prodvar = MXBUYMEDIA; } else { $price = $media->cartprice; //MXFEE1SONG; $prodvar = MXBUYMEDIA; } } $mxuser->addcart($cart->id, MXMEDSUB, $prodref, $prodvar, $price); $cart->progress = 1; break; case 'medunbuy': $prodref = preg_replace('%[^0-9]%', '', mx_secureword($_REQUEST['m'])); $prodline = 0; foreach ($cart->lines as $line) { if ($line->prodtype == MXMEDSUB && $line->prodref == $prodref) { $prodline = $line->id; } } if ($prodline) { $mxuser->deletecart($cart->id, array($prodline)); } $cart->progress = 1; break; case 'delcart': $cartlines = $_POST['cartline']; $mxuser->deletecart($cart->id, $cartlines); $cart->progress = 1; break; case 'delwish': $wishlines = $_POST['wishline']; $mxuser->deletewish($wishlines); $cart->progress = 1; break; case 'tocart': $wishlines = $_POST['wishline']; $mxuser->wishtocart($cart->id, $wishlines); $_REQUEST['k'] = 'cart'; $cart->progress = 1; break; case 'towish': $cartlines = $_POST['cartline']; $mxuser->carttowish($cart->id, $cartlines); $cart->progress = 1; break; case 'shopmore': case 'shopmore_w': header('location: ' . mx_optionurl('artists', 'artsdir')); $cart->progress = 1; break; case 'checkout': $cart->progress = 2; $mxuser->setcart($cart->id, 'status', MXCARTCHECKOUTADDRESS); break; case 'pp-checkout': $mxuser->setcart($cart->id, 'status', MXCARTCHECKOUTPAYPAL); $cart->err = mx_checkout($cart); // at this point we should have been redirected to paypal, otherwise: not good :( $cart->progress = 2; break; case 'ppcall': /* die(phpinfo()); preg_match_all('%([a-zA-Z0-9_]+)=([^&]+)%',$_SERVER['REQUEST_URI'],$ppparams); foreach ($ppparams[1] as $key => $elem) { $ppal[$elem]=$ppparams[2][$key]; } */ $orderinfo = mx_orderreview(); $cart->orderinfo = $orderinfo; $billadd = array('addresstype' => MXBILLINGADDRESS, 'cartid' => $cart->id, 'email' => $orderinfo['EMAIL'], 'salutation' => $orderinfo['SALUTATION'], 'first' => $orderinfo['FIRSTNAME'], 'middle' => $orderinfo['MIDDLENAME'], 'last' => $orderinfo['LASTNAME'], 'suffix' => $orderinfo['SUFFIX'], 'business' => $orderinfo['BUSINESS'], 'pppayerid' => $orderinfo['PAYERID'], 'pppayerstatus' => $orderinfo['PAYERSTATUS']); $shipadd = array('addresstype' => MXSHIPPINGADDRESS, 'cartid' => $cart->id, 'shiptoname' => $orderinfo['SHIPTONAME'], 'street1' => $orderinfo['SHIPTOSTREET'], 'street2' => $orderinfo['SHIPTOSTREET2'], 'city' => $orderinfo['SHIPTOCITY'], 'state' => $orderinfo['SHIPTOSTATE'], 'countrycode' => $orderinfo['SHIPTOCOUNTRYCODE'], 'zip' => $orderinfo['SHIPTOZIP'], 'addressstatus' => $orderinfo['ADDRESSSTATUS'], 'phone' => $orderinfo['SHIPTOPHONENUM']); $mxuser->clearaddresses($cart->id); $billid = $mxuser->addaddress($billadd); $shipid = $mxuser->addaddress($shipadd); $mxuser->setcart($cart->id, 'billingid', $billid); $mxuser->setcart($cart->id, 'shippingid', $shipid); $mxuser->setcart($cart->id, 'status', MXCARTCONFIRM); $mxuser->setcart($cart->id, 'memo', $orderinfo['PAYMENTREQUEST_0_NOTETEXT']); $mxuser->setcart($cart->id, 'invoicenum', $orderinfo['INVNUM']); $mxuser->setcart($cart->id, 'taxcountrycode', $shipadd['countrycode']); $cart->taxcountrycode = $shipadd['countrycode']; $cart->progress = 3; break; case 'ppcancel': // cancelled in paypal // cancelled in paypal case 'canckout': // cancelled at order review /* preg_match_all('%([a-zA-Z0-9_]+)=([^&]+)%',$_SERVER['REQUEST_URI'],$ppparams); foreach ($ppparams[1] as $key => $elem) { $ppal[$elem]=$ppparams[2][$key]; } */ //die(phpinfo()); $cart->progress = 1; // cancel token for paypal session $mxuser->setcart($cart->id, 'token', ''); $mxuser->setcart($cart->id, 'status', $action == 'ppcancel' ? MXCARTCANCELLEDFROMPAYPAL : MXCARTCANCELLEDFROMCONFIRM); // remove billing/shipping addresses $mxuser->deladdress($cart->billingid); $mxuser->deladdress($cart->shippingid); $mxuser->setcart($cart->id, 'billingid', ''); $mxuser->setcart($cart->id, 'shippingid', ''); $cart->info = _('You just canceled the checkout process.<br/>' . 'You can make changes to your cart, adding new items to it<br/>' . ' or moving some items to your wish list for a later purchase.'); break; case 'confckout': case 'printorder': /* die(phpinfo()); preg_match_all('%([a-zA-Z0-9_]+)=([^&]+)%',$_SERVER['REQUEST_URI'],$ppparams); foreach ($ppparams[1] as $key => $elem) { $ppal[$elem]=$ppparams[2][$key]; } */ $cart->paymentoption = mx_securestring($_POST['paymentoption']); if (!$cart->transactionid) { // first submit (saving payment to DB) if ($cart->total > 0) { $orderconfirm = mx_orderconfirmation($cart); $cart->orderconfirm = $orderconfirm; $paymentinfo = array('transactionid' => $orderconfirm['PAYMENTINFO_0_TRANSACTIONID'], 'ordertime' => preg_replace('%[^0-9]%', '', $orderconfirm['PAYMENTINFO_0_ORDERTIME']), 'total' => $orderconfirm['PAYMENTINFO_0_AMT'], 'paypalfee' => $orderconfirm['PAYMENTINFO_0_FEEAMT'], 'taxes' => $orderconfirm['PAYMENTINFO_0_TAXAMT'], 'currency' => $orderconfirm['PAYMENTINFO_0_CURRENCYCODE'], 'paymentstatus' => $orderconfirm['PAYMENTINFO_0_PAYMENTSTATUS'], 'pendingreason' => $orderconfirm['PAYMENTINFO_0_PENDINGREASON'], 'reasoncode' => $orderconfirm['PAYMENTINFO_0_REASONCODE'], 'receiptid' => $orderconfirm['PAYMENTINFO_0_RECEIPTID'], 'status' => MXCARTCONFIRMED); } else { // subscriptions only $cart->orderconfirm = array(); $paymentinfo = array('paymentstatus' => 'Pending', 'pendingreason' => 'RecurrentPaymentValidation', 'status' => MXCARTCONFIRMED); } $mxuser->setcartbatch($cart->id, $paymentinfo); mx_addsubs($mxuser->id, $cart->id); if ($paymentinfo['paymentstatus'] == 'Completed') { mx_confirmcart($mxuser->id, $cart->id); } foreach ($cart->lines as $line) { if ($line->prodtype == MXARTSUB && $line->prodvar == MXSUBFOY || $line->prodtype == MXSITESUB && $line->prodvar != MXSUBFREE) { $ppinfo = mx_recurrentpayment($cart, $line); mx_setsubinfo($mxuser->id, $line, $ppinfo); } } } else { // already confirmed do not submit again, but get the data from the DB instead... if ($cart->total > 0) { $orderconfirm = array('PAYMENTINFO_0_PAYMENTSTATUS' => $cart->paymentstatus, 'PAYMENTINFO_0_TRANSACTIONID' => $cart->transactionid, 'PAYMENTINFO_0_ORDERTIME' => $cart->ordertime, 'PAYMENTINFO_0_AMT' => $cart->total, 'PAYMENTINFO_0_TAXAMT' => $cart->taxes, 'PAYMENTINFO_0_CURRENCYCODE' => $cart->currency); } else { // subscriptions only $orderconfirm = array(); } $cart->orderconfirm = $orderconfirm; } $cart->info = _('Thanks for your order.<br/>We will activate your subscriptions and purchases' . '<br/>as soon as we get the confirmation of your payment.<br/>' . 'Please print this page for your records'); $cart->progress = 4; break; default: $cart->progress = 1; break; } // get new cart details if ($action != 'pp-checkout' && $action != 'confckout') { $cart->lines = $mxuser->getcartdetails($cart->id); } foreach ($cart->lines as $ndx => $line) { $note = ''; if ($line->prodtype == MXMEDSUB) { $media = $mxuser->getmediainfo($line->prodref); foreach ($cart->lines as $other) { //error_log('other: '.$other->prodtype.' '.$other->prodref); //error_log('bun[0]: '.$media->bundles[0]->id); if ($other->prodtype == MXARTSUB && $other->prodref == $media->owner_id) { $note = buywarn(sprintf(_('This media is already included in your subscription to %s'), $media->artistname)); //error_log('included sub!!'); } else { if ($other->prodtype == MXMEDSUB && $other->prodref == $media->bundles[0]->id) { $note = buywarn(sprintf(_('This media is already part of bundle "%s"'), $media->bundles[0]->title)); //error_log('included bundle!!'); } } } if ($media->owner_id == $mxuser->id) { $note = buywarn(_('Buying your own media...?')); } } else { if ($line->prodtype == MXARTSUB) { if ($line->prodref == $mxuser->id) { $note = buywarn(_('Hey! That\'s your own account...')); } } } $cart->lines[$ndx]->note = $note; } $cart->items = count($cart->lines); $cart->wishes = $mxuser->getwishlist(); //$cart->items=count($cart->lines); $mxuser->cart = $cart; }