コード例 #1
0
ファイル: checkout.php プロジェクト: rbredow/allyzabbacart
 // = Start Spreedly Processing =
 // =============================
 if (Cart66Session::get('Cart66Cart')->hasSpreedlySubscriptions()) {
     $accountErrors = $account->validate();
     if (count($accountErrors) == 0) {
         $account->save();
         // Save account data locally which will create an account id and/or update local values
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Account data validated and saved for account id: " . $account->id);
         try {
             $spreedlyCard = new SpreedlyCreditCard();
             $spreedlyCard->hydrateFromCheckout();
             $subscriptionId = Cart66Session::get('Cart66Cart')->getSpreedlySubscriptionId();
             $productId = Cart66Session::get('Cart66Cart')->getSpreedlyProductId();
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] About to create a new spreedly account subscription: Account ID: {$account->id} | Subscription ID: {$subscriptionId}");
             $accountSubscription = new Cart66AccountSubscription();
             $accountSubscription->createSpreedlySubscription($account->id, $subscriptionId, $productId, $spreedlyCard);
         } catch (SpreedlyException $e) {
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Failed to checkout: " . $e->getCode() . ' ' . $e->getMessage());
             $errors['spreedly failed'] = $e->getMessage();
             $accountSubscription->refresh();
             if (empty($accountSubscription->subscriberToken)) {
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] About to delete local account after spreedly failure: " . print_r($account->getData(), true));
                 $account->deleteMe();
             } else {
                 // Set the subscriber token in the session for repeat attempts to create the subscription
                 Cart66Session::set('Cart66SubscriberToken', $account->subscriberToken);
             }
             if (count($errors)) {
                 try {
                     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Unable to process order: " . print_r($errors, true));
                     throw new Cart66Exception(__('Your order could not be processed for the following reasons:', 'cart66'), 66500);