コード例 #1
0
 /**
  * Return an array of enabled spreedly subscriptions
  * 
  * @return array
  */
 public static function getSubscriptions()
 {
     if (empty(self::$_subscriptionPlans)) {
         $result = SpreedlyCommon::curlRequest("/subscription_plans.xml", "get");
         if ($result->code == '200') {
             $subscriptions = array();
             $plans = new SimpleXmlElement($result->response);
             foreach ($plans as $plan) {
                 $subscription = new SpreedlySubscription();
                 $subscription->setData($plan);
                 /// Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Spreedly subscription enabled: " . $subscription->enabled);
                 if ('true' == (string) $subscription->enabled) {
                     $subscriptions[] = $subscription;
                 }
             }
             self::$_subscriptionPlans = $subscriptions;
         } else {
             throw new SpreedlyException('Spreedly Subscription: Unable to retrieve remote list of subscriptions', 66003);
         }
     }
     return self::$_subscriptionPlans;
 }
コード例 #2
0
 /**
  * Pay a spreedly invoice. The invoice token is required for payment.
  * Returns the paid invoice token.
  * 
  * @param mixed $paymentMethod Either "on-file" or a SpreedlyCreditCard object
  * @param string $invoiceToken 
  * @return string The invoice token that was paid.
  * @throws SpreedlyException on failure
  */
 public function pay($paymentMethod, $invoiceToken = null)
 {
     $payment = array('account-type' => 'on-file');
     if (get_class($paymentMethod) == 'SpreedlyCreditCard') {
         if (!$paymentMethod->validate()) {
             $errorDetails = print_r($paymentMethod->getErrors(), true);
             throw new SpreedlyException('Spreedly Payment: Invalid credit card data trying to be used to pay a spreedly invoice: ' . $errorDetails, 66001);
         }
         $cardData = $paymentMethod->getCardData();
         $payment = array('account-type' => 'credit-card', 'credit-card' => $cardData);
     }
     // Set invoice token if provided
     if (isset($invoiceToken)) {
         $this->setToken($invoiceToken);
     }
     // Make sure there is an invoice token before trying to process the payment
     if (empty($this->_invoiceToken)) {
         throw new SpreedlyException('Spreedly Payment: Trying to pay spreedly invoice without a valid invoice token', 66002);
     }
     $xml = Cart66Common::arrayToXml($payment, 'payment');
     $result = SpreedlyCommon::curlRequest('/invoices/' . $this->_invoiceToken . '/pay.xml', "put", $xml);
     $responseCode = $result->code;
     if (!empty($responseCode)) {
         if ($responseCode != 200) {
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Spreedly Invoice Payment: Failed to pay invoice. \n          Code: " . $responseCode . "\nResponse: " . $result->response . "\n Payment XML:\n{$xml}");
             $errorResponse = $result->response;
             throw new SpreedlyException("Spreedly Payment: Failed to pay spreedly invoice. \n\n{$errorResponse}", $responseCode);
         }
         try {
             $invoice = new SimpleXMLElement($result->response);
             $this->_invoiceToken = $invoice->token;
         } catch (Exception $e) {
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] SpreedlyInvoice pay(): \n          Unable to create SimpleXmlElement from result response: " . $result->response);
         }
     }
 }
コード例 #3
0
 /**
  * All fields are optional - any field that is not provided will not be updated.
  */
 public static function updateRemoteAccount($customerId, $subscriberData)
 {
     $subscriberXml = Cart66Common::arrayToXml($subscriberData, 'subscriber');
     $result = SpreedlyCommon::curlRequest("/subscribers/{$customerId}.xml", "put", $subscriberXml);
     if ($result->code != '200') {
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Spreedly Subscriber: Account information could not be updated. " . $result->response . "\nCode: {$result->code}");
         throw new SpreedlyException('Spreedly Subscriber: Account information could not be updated.', $result->code);
     }
 }