function create_paypal_AutoBill($account, $paymentmethod)
{
    $ipAddress = '127.0.0.1';
    $uniqueValue = get_unique_value();
    $merchantAutoBillId = 'ab-' . $uniqueValue;
    $merchantProductId = 'mm_1_day_recurring';
    //'Video';
    $merchantBillingPlanId = 'Daily';
    //'OneMonthSubOneMonthRecurring';
    $autobill = new AutoBill();
    $autobill->setMerchantAutoBillId($merchantAutoBillId);
    $autobill->setAccount($account);
    $product = new Product();
    $product->setMerchantProductId($merchantProductId);
    $billingplan = new BillingPlan();
    $billingplan->setMerchantBillingPlanId($merchantBillingPlanId);
    $item = new AutoBillItem();
    $item->setIndex(0);
    $item->setProduct($product);
    $autobill->setItems(array($item));
    $autobill->setSourceIp($ipAddress);
    $autobill->setBillingPlan($billingplan);
    $autobill->setCurrency('USD');
    $autobill->setPaymentMethod($paymentmethod);
    // Set PaymentMethod used by AutoBill
    //$duplicateBehavior = 'Fail'; //removed in 9.0
    //$validatePaymentMethod = true; //removed in 9.0
    $immediateAuthFailurePolicy = 'doNotSaveAutoBill';
    //added in 9.0
    $validateForFuturePayment = true;
    //added in 9.0
    $minChargebackProbability = 100;
    $ignoreAvsPolicy = true;
    $ignoreCvnPolicy = true;
    $campaignCode = null;
    $dryrun = false;
    $response = $autobill->update($immediateAuthFailurePolicy, $validateForFuturePayment, $minChargebackProbability, $ignoreAvsPolicy, $ignoreCvnPolicy, $campaignCode, $dryrun);
    if ($response['returnCode'] != '200') {
        print 'Error creating autobill' . PHP_EOL;
        print 'Soap Id = ' . $response['data']->return->soapId . PHP_EOL;
        print 'Return Code = ' . $response['returnCode'] . PHP_EOL;
        print 'Return String = ' . $response['returnString'] . PHP_EOL;
    } else {
        $response_object = $response['data'];
        $auth_status = $response_object->authStatus;
        if ($auth_status->status == 'AuthorizationPending') {
            $redirection_url = $auth_status->payPalStatus->redirectUrl;
            echo "To authorize, please visit: <a href=\"" . $redirection_url . "\">Continue to Paypal</a>" . PHP_EOL;
        } else {
            if ($auth_status->status == 'Cancelled') {
                echo "Autobill not accepted by PayPal";
            } else {
                echo "Status = " . $auth_status->status;
            }
        }
    }
    return $redirection_url;
}
function create_ecp_AutoBill($account)
{
    $ipAddress = '127.0.0.1';
    $uniqueValue = get_unique_value();
    $merchantAutoBillId = 'ab-' . $uniqueValue;
    $merchantProductId = 'git_hub_product';
    $merchantBillingPlanId = 'git_hub_example';
    $autobill = new AutoBill();
    $autobill->setMerchantAutoBillId($merchantAutoBillId);
    $autobill->setAccount($account);
    $product = new Product();
    $product->setMerchantProductId($merchantProductId);
    $billingplan = new BillingPlan();
    $billingplan->setMerchantBillingPlanId($merchantBillingPlanId);
    $item = new AutoBillItem();
    $item->setIndex(0);
    $item->setProduct($product);
    $autobill->setItems(array($item));
    $autobill->setSourceIp($ipAddress);
    $autobill->setBillingPlan($billingplan);
    $autobill->setCurrency('USD');
    //$duplicateBehavior = 'Fail'; //removed in 9.0
    //$validatePaymentMethod = true; //removed in 9.0
    $immediateAuthFailurePolicy = 'doNotSaveAutoBill';
    //added in 9.0
    $validateForFuturePayment = true;
    //added in 9.0
    $minChargebackProbability = 100;
    $ignoreAvsPolicy = true;
    $ignoreCvnPolicy = true;
    $campaignCode = null;
    $dryrun = false;
    $response = $autobill->update($immediateAuthFailurePolicy, $validateForFuturePayment, $minChargebackProbability, $ignoreAvsPolicy, $ignoreCvnPolicy, $campaignCode, $dryrun);
    if ($response['returnCode'] != '200') {
        print 'Error creating autobill' . PHP_EOL;
        print 'Soap Id = ' . $response['data']->return->soapId . PHP_EOL;
        print 'Return Code = ' . $response['returnCode'] . PHP_EOL;
        print 'Return String = ' . $response['returnString'] . PHP_EOL;
    } else {
        $response_object = $response['data'];
        $auth_status = $response_object->authStatus;
        if ($auth_status->status == 'AuthorizedForValidation') {
            echo "ECP payment in AuthorizedForValidation status, this is a successful test of ECP." . PHP_EOL;
        } else {
            if ($auth_status->status == 'Cancelled') {
                echo "Validation of ECP failed.";
            } else {
                echo "Status = " . $auth_status->status;
            }
        }
    }
    return $auth_status->status;
}
$billingplanID = $argv[3];
print "billingplanID is {$billingplanID} \n";
$billingplan = new BillingPlan();
$billingplan->setMerchantBillingPlanId($billingplanID);
// Create a random ID for our testing - This should be much more unique in a production env.
$autobillID = 'ab-random' . rand(1000, 9999999);
print "autobillID is {$autobillID} \n";
$autobill = new AutoBill();
$autobill->setItems(array($item));
$autobill->setAccount($account);
$autobill->setBillingPlan($billingplan);
$autobill->setMerchantAutoBillId($autobillID);
// You can apply a Campaign Code to the Billing Plan here:
//$autobill->setBillingPlanCampaignCode('1MonthBonusPromo');
// IP is used along with address info for fraud scoring
$autobill->setSourceIp('123.123.123.123');
// Choices for a faiure of the initial auth.  Uncomment only one at a time:
$immediateAuthFailurePolicy = 'doNotSaveAutoBill';
// pre-9.0 behavior for an initial auth failure
//$immediateAuthFailurePolicy = 'putAutoBillInRetryCycle'; // Creates AutoBill and retriesthe authorizaton.
//$immediateAuthFailurePolicy = 'putAutoBillInRetryCycleIfPaymentMethodIsValid'; // recommended in the API guide
$validateForFuturePayment = 1;
//  need to validate to get the above choices
$fraudScore = 100;
// minChargebackProbability of 100 skips fraud scoring completely
$ignoreAVS = 0;
$ignoreCVN = 0;
$dryrun = 1;
$dryrun = $argv[4];
print "dryrun is {$dryrun} \n";
$coupon = NULL;