function prepayNonRecurringWithNonRecurringPrice($merchantAutobillId) { // Fetch the current active non-recurring autobill by fetching all autobills by merchantAccountId. // Pick the current active non-recurring autobill for which they are pre-paying. $currentActiveNonRecurringAutobill = get_current_active_nonrecurring_autobill($merchantAutobillId); // Pre-pay capturing a transaction for price of product on current active non-recurring autobill. $merchantTransactionId = prepay($currentActiveNonRecurringAutobill); $startTimestamp = $currentActiveNonRecurringAutobill->endTimestamp; $merchantAutoBillId = $currentActiveNonRecurringAutobill->merchantAutoBillId . '+'; $merchantAccountId = $currentActiveNonRecurringAutobill->account->merchantAccountId; // Only use sparse object, so all data members are not over-written. $sparseAccount = new Account(); $sparseAccount->merchantAccountId = $currentActiveNonRecurringAutobill->account->merchantAccountId; // Assume same billing plan as on current autobill. $billingPlan = $currentActiveNonRecurringAutobill->billingPlan; // Assume same product as on current autobill. $product = $currentActiveNonRecurringAutobill->items[0]->product; $itemNonRecurring = new AutoBillItem(); $itemNonRecurring->setIndex(1); // Override price of product to 0 USD, since payment is taken up front as one-time transaction. $itemNonRecurring->setAmount(0); $itemNonRecurring->setProduct($product); $autobill = new AutoBill(); $autobill->setMerchantAutoBillId($merchantAutoBillId); $autobill->setAccount($sparseAccount); $autobill->setItems(array($itemNonRecurring)); $autobill->setBillingPlan($billingPlan); // Future dated autobill will start when the current active autobill ends. // Price is overrided as 0 USD, so no transaction will occur and the user will be entitled for the next non-recurring cycle. $autobill->setStartTimestamp($startTimestamp); $autobill->setWarnOnExpiration(true); $autobill->setCurrency('USD'); // Add a name value pair to signify a linkage to the previous Autobill. // Add a name value pair to signify a linkage to the Transaction used to collect payment. // This will help out with revenue recognition. $nameVals[0] = new NameValuePair(); $nameVals[0]->setName("PreviousNonRecurringAutobillId"); $nameVals[0]->setValue($currentActiveNonRecurringAutobill->merchantAutoBillId); $nameVals[1] = new NameValuePair(); $nameVals[1]->setName("PaidForByMerchantTransactionId"); $nameVals[1]->setValue($merchantTransactionId); $autobill->setNameValues($nameVals); $immediateAuthFailurePolicy = 'doNotSaveAutoBill'; $validateForFuturePayment = false; $minChargebackProbability = 100; $ignoreAvsPolicy = true; $ignoreCvnPolicy = true; $campaignCode = null; $dryrun = false; $response = $autobill->update($immediateAuthFailurePolicy, $validateForFuturePayment, $minChargebackProbability, $ignoreAvsPolicy, $ignoreCvnPolicy, $campaignCode, $dryrun); logCall($response, 'Autobill::Update', $merchantAccountId); }