/** * Create a recurring payments profile * The initial payment is charged with DoExpressCheckout so that the first payment is received immediately */ public function CreateRecurringPaymentsProfile($token, $cartItem, $index) { $plan = new Cart66PayPalSubscription($cartItem->getPayPalSubscriptionId()); $queryString = array('TOKEN' => $token, 'METHOD' => 'CreateRecurringPaymentsProfile', 'PROFILESTARTDATE' => date('Y-m-d\\Tg:i:s', strtotime($plan->getStartTimeFormula(), Cart66Common::localTs())), 'BILLINGPERIOD' => ucwords(rtrim($plan->billingIntervalUnit, 's')), 'BILLINGFREQUENCY' => $plan->billingInterval, 'TOTALBILLINGCYCLES' => $plan->billingCycles, 'AMT' => $plan->price, 'INITAMT' => 0, 'CURRENCYCODE' => CURRENCY_CODE, 'FAILEDINITAMTACTION' => 'CancelOnFailure', 'L_BILLINGTYPE' . $index => 'RecurringPayments', 'DESC' => $plan->name . ' ' . str_replace(' ', ' ', strip_tags($plan->getPriceDescription($plan->offerTrial > 0, '(trial)')))); if ($plan->offerTrial == 1) { $queryString['TRIALBILLINGPERIOD'] = ucwords(rtrim($plan->trialPeriodUnit, 's')); $queryString['TRIALBILLINGFREQUENCY'] = $plan->trialPeriod; $queryString['TRIALAMT'] = $plan->trialPrice; $queryString['TRIALTOTALBILLINGCYCLES'] = $plan->trialCycles; } $params = array(); $queryString = array_merge($this->_apiData, $queryString); foreach ($queryString as $key => $value) { $params[] = $key . '=' . urlencode($value); } $nvp = implode('&', $params); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Creating recurring payments profile NVP: " . str_replace('&', "\n", $nvp)); $result = $this->_decodeNvp($this->_sendRequest($this->_apiEndPoint, $nvp)); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Creating recurring payments raw result: " . print_r($result, true)); return $result; }
Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Creating account after successful PayPal transaction"); $account->save(); } // Create Recurring Payment Profile if a subscription has been sold $profileResponse = array('ACK' => 'SKIPPED'); if ($cartItem = Cart66Session::get('Cart66Cart')->getPayPalSubscriptionItem()) { $planIndex = Cart66Session::get('Cart66Cart')->getPayPalSubscriptionIndex(); $plan = new Cart66PayPalSubscription($cartItem->getPayPalSubscriptionId()); $profileResponse = $pp->CreateRecurringPaymentsProfile($token, $cartItem, $planIndex); if ('FAILURE' != strtoupper($profileResponse['ACK'])) { $paypalPaymentProfileId = $profileResponse['PROFILEID']; if (Cart66Common::isLoggedIn() && $account->isPayPalAccount()) { // Expire the current subscription and attach a new subscription $account->cancelSubscription('Your subscription has been canceled because you changed to a new subscription.', true); } $activeUntil = $plan->getStartTimeFormula(); $account->attachPayPalSubscription($details, $paypalPaymentProfileId, $plan, $activeUntil); } } elseif ($cartItem = Cart66Session::get('Cart66Cart')->getMembershipProductItem()) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Got membership product from the cart after a PayPal transaction."); $product = new Cart66Product($cartItem->getProductId()); $account->attachMembershipProduct($product, $details['FIRSTNAME'], $details['LASTNAME']); } // Save the order if ('FAILURE' != strtoupper($profileResponse['ACK'])) { $token = Cart66Common::postVal('token'); $payerId = Cart66Common::postVal('PayerID'); $opts = Cart66Setting::getValue('status_options'); $status = ''; if (!empty($opts)) { $opts = explode(',', $opts);