setParam('action', 'step1'); if ($promotionId){ $api->setParam('promotionId', $promotionId); } if ($promocode){ $api->setParam('promocode', $promocode); } $promoStr=''; if ($promotionId){ $promoStr='&promotionId='.$promotionId; if ($promocode){ $promoStr=$promoStr.'&promocode='.$promocode; } } if ($_POST['cctype']){ // add credit card params $api->setParam('ccfirstname', $_POST['ccfirstname']); $api->setParam('cclastname', $_POST['cclastname']); $api->setParam('ccaddress', $_POST['ccaddress']); $api->setParam('cccity', $_POST['cccity']); $api->setParam('ccstate', $_POST['ccstate']); $api->setParam('cccountry_code', $_POST['cccountry_code']); $api->setParam('cczipcode', $_POST['cczipcode']); $api->setParam('cctype', $_POST['cctype']); $api->setParam('ccnumber', $_POST['ccnumber']); $api->setParam('ccexpdate_month', $_POST['ccexpdate_month']); $api->setParam('ccexpdate_year', $_POST['ccexpdate_year']); $api->setParam('cccvv2', $_POST['cccvv2']); $api->setParam('client_ip_addr', $_SERVER["REMOTE_ADDR"]); }else{ $api->setParam('returnUrl', selfURL().'?action=step2&bundleId='.$bundleId.'&pricepointId='.$pricepointId.$promoStr.'&purchaseDetail='.$_GET['purchaseDetail']); $api->setParam('cancelUrl', selfURL().'?action=cancel'); } $api->setParam('paymentDescription', $_GET['purchaseDetail']); $res=$api->purchase($priceplanId, $endUserAreaId, getUserId(), $bundleId, $pricepointId); if ($api->hasErrors()){ sendError($api->getErrorMessage()); return; } $error=''; $link=''; if (!$res){ $error=__('There was an error while trying to purchase the content', 'bachbill'); } if ($res['error']){ $error=$res['error']['message']; }else { $res=$res['PurchaseResponse']; if ($res['code']==0){ $res=$res['paypal']; if (!$res){ // $error=__('There was an error while trying to purchase the content', 'bachbill'); // purchase cost zero, so redirect to the content @session_start(); $redirect=$_SESSION['bachbill_redirect_after_purchase']; if (isset($redirect)){ wp_redirect($redirect); return; } }else { if ($res['url']){ wp_redirect($res['url']); return; } $transactionId=$res['transactionId']; $profileId=$res['profileId']; $profileStatus=$res['profileStatus']; if (!$transactionId && !($profileStatus=='ActiveProfile')){ $error=__('There was an error while trying to purchase the content', 'bachbill'); }else { @session_start(); $redirect=$_SESSION['bachbill_redirect_after_purchase']; if (isset($redirect)){ wp_redirect($redirect); return; } } } }else { $error=__('There was an error while trying to purchase the content', 'bachbill'); } } }else if ($action=='step2'){ $promotionId=$_GET['promotionId']; $promocode=$_GET['promocode']; $token=$_GET['token']; $PayerID=$_GET['PayerID']; $api->setParam('action', 'step2'); if ($promotionId){ $api->setParam('promotionId', $promotionId); } if ($promocode){ $api->setParam('promocode', $promocode); } $api->setParam('token', $token); $api->setParam('PayerID', $PayerID); $api->setParam('paymentDescription', $_GET['purchaseDetail']); $res=$api->purchase($priceplanId, $endUserAreaId, getUserId(), $bundleId, $pricepointId); if ($api->hasErrors()){ sendError($api->getErrorMessage()); return; } $error=''; if (!$res){ $error=__('There was an error while trying to purchase the content', 'bachbill'); } if ($res['error']){ $error=$res['error']['message']; }else { $res=$res['PurchaseResponse']; if ($res['code']=='0'){ $res=$res['paypal']; if (!$res){ $error=__('There was an error while trying to purchase the content', 'bachbill'); }else { $transactionId=$res['transactionId']; $profileId=$res['profileId']; $profileStatus=$res['profileStatus']; if (!$transactionId && !$profileStatus){ $error=__('There was an error while trying to purchase the content', 'bachbill'); }else { @session_start(); $redirect=$_SESSION['bachbill_redirect_after_purchase']; if (isset($redirect)){ wp_redirect($redirect); return; } } } }else { $error=__('There was an error while trying to purchase the content', 'bachbill'); } } }else if ($action=='cancel'){ @session_start(); $error=__('The action was cancelled by the user', 'bachbill'); $link=$_SESSION['bachbill_redirect_after_purchase']; }else if ($action=='render'){ }else { $error=__('The action is not valid', 'bachbill'); } //$redirect=$_SESSION['bachbill_redirect_after_purchase']; // if (isset($redirect)){ // wp_redirect($redirect); // } get_header(); ?>