/**
  * Log the PayPal recurring payment. 
  * 
  * The $data array paramter is a URL decoded version of the IPN post data.
  *   - Log the data in the pp_recurring_posts table
  *   - Update the account_subscriptions table with the new active_until date
  */
 public function log(array $ipnData)
 {
     $isLogged = false;
     $subscription = new Cart66AccountSubscription();
     if ($subscription->loadByPayPalBillingProfileId($ipnData['recurring_payment_id'])) {
         $data = array('account_id' => $subscription->accountId, 'recurring_payment_id' => $ipnData['recurring_payment_id'], 'mc_gross' => $ipnData['mc_gross'], 'txn_id' => $ipnData['txn_id'], 'product_name' => $ipnData['product_name'], 'first_name' => $ipnData['first_name'], 'last_name' => $ipnData['last_name'], 'payer_email' => $ipnData['payer_email'], 'ipn' => serialize($ipnData), 'next_payment_date' => $ipnData['next_payment_date'], 'time_created' => date('Y-m-d H:i:s', strtotime($ipnData['time_created'])));
         $this->setData($data);
         $id = $this->save();
         if ($id > 0) {
             $isLogged = true;
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Recurring payment logged with ID: {$id}");
             $subscription->extendActiveUntil($ipnData['next_payment_date']);
         } else {
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Failed to log recurring payment. " . print_r($data, true));
         }
     } else {
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Unable to log recurring payment because the paypal billing profile id is unknown: " . $ipnData['recurring_payment_id']);
     }
     return $isLogged;
 }
Exemplo n.º 2
0
 /**
  * Set active flag to zero and status to canceled.
  * The active_until date is not changed. Therefore, a canceled subscription
  * will remain active until the amount of time paid for has expired.
  * 
  * @param array $rawPost The IPN post data from PayPal
  * @return int or false The id of the subscription that was canceled or false if cancelation failed
  */
 public function cancelSubscription($rawPost)
 {
     $canceledId = false;
     $decodedPost = $this->_decodeRawPost($rawPost);
     $subId = $decodedPost['recurring_payment_id'];
     $sub = new Cart66AccountSubscription();
     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] IPN request to cancel subscription {$subId}");
     if ($sub->loadByPayPalBillingProfileId($subId)) {
         $sub->active = 0;
         $sub->status = 'canceled';
         $sub->save();
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Canceled subscription {$subId} via IPN request.");
         $canceledId = $sub->id;
     }
     return $canceledId;
 }