Exemple #1
0
 public function charges($params = null)
 {
     if (!$params) {
         $params = array();
     }
     $params['customer'] = $this->id;
     $charges = Stripe_Charge::all($params, $this->_apiKey);
     return $charges;
 }
Exemple #2
0
 public function get_all_transactions($num_charges = 100, $offset = 0)
 {
     try {
         $ch = Stripe_Charge::all(array('count' => $num_charges, 'offset' => $offset));
         $data['error'] = FALSE;
         $raw_data = array();
         foreach ($ch->data as $record) {
             $raw_data[] = $this->charge_to_array($record);
         }
         $data['data'] = $raw_data;
         return $data;
     } catch (Exception $e) {
         $this->error = TRUE;
         $this->message = $e->getMessage();
         $this->code = $e->getCode();
         return FALSE;
     }
 }
 /**
  * Process the changes from the Modify Pro Site Status metabox.
  *
  * @param $blog_id
  */
 public static function process_modify($blog_id)
 {
     global $psts, $current_user;
     $success_msg = $error_msg = '';
     if (isset($_POST['stripe_mod_action'])) {
         $customer_id = self::get_customer_data($blog_id)->customer_id;
         $exitsing_invoice_object = Stripe_Invoice::all(array("customer" => $customer_id, "count" => 1));
         $last_payment = $exitsing_invoice_object->data[0]->total / 100;
         $refund_value = $_POST['refund_amount'];
         $refund_amount = $refund_value * 100;
         $refund_amount = (int) $refund_amount;
         $refund = $last_payment;
         switch ($_POST['stripe_mod_action']) {
             case 'cancel':
                 $end_date = date_i18n(get_option('date_format'), $psts->get_expire($blog_id));
                 try {
                     $customer_data = self::get_customer_data($blog_id);
                     $customer_id = $customer_data->customer_id;
                     $sub_id = $customer_data->subscription_id;
                     $cu = Stripe_Customer::retrieve($customer_id);
                     // Don't use ::cancelSubscription because it doesn't know which subscription if we have multiple
                     $cu->subscriptions->retrieve($sub_id)->cancel();
                     //record stat
                     $psts->record_stat($blog_id, 'cancel');
                     $psts->log_action($blog_id, sprintf(__('Subscription successfully cancelled by %1$s. They should continue to have access until %2$s', 'psts'), $current_user->display_name, $end_date));
                     $success_msg = sprintf(__('Subscription successfully cancelled. They should continue to have access until %s.', 'psts'), $end_date);
                     update_blog_option($blog_id, 'psts_stripe_canceled', 1);
                 } catch (Exception $e) {
                     $error_msg = $e->getMessage();
                     $psts->log_action($blog_id, sprintf(__('Attempt to Cancel Subscription by %1$s failed with an error: %2$s', 'psts'), $current_user->display_name, $error_msg));
                 }
                 break;
             case 'cancel_refund':
                 $end_date = date_i18n(get_option('date_format'), $psts->get_expire($blog_id));
                 $cancellation_success = false;
                 try {
                     $customer_data = self::get_customer_data($blog_id);
                     $customer_id = $customer_data->customer_id;
                     $sub_id = $customer_data->subscription_id;
                     $cu = Stripe_Customer::retrieve($customer_id);
                     // Don't use ::cancelSubscription because it doesn't know which subscription if we have multiple
                     $cu->subscriptions->retrieve($sub_id)->cancel();
                     $cancellation_success = true;
                     //record stat
                 } catch (Exception $e) {
                     $error_msg = $e->getMessage();
                 }
                 if ($cancellation_success == false) {
                     $psts->log_action($blog_id, sprintf(__('Attempt to Cancel Subscription and Refund Prorated (%1$s) Last Payment by %2$s failed with an error: %3$s', 'psts'), $psts->format_currency(false, $refund), $current_user->display_name, $error_msg));
                     $error_msg = sprintf(__('Whoops, Stripe returned an error when attempting to cancel the subscription. Nothing was completed: %s', 'psts'), $error_msg);
                     break;
                 }
                 $refund_success = false;
                 if ($cancellation_success == true) {
                     try {
                         $charge_object = Stripe_Charge::all(array("count" => 1, "customer" => $customer_id));
                         $charge_id = $charge_object->data[0]->id;
                         $ch = Stripe_Charge::retrieve($charge_id);
                         $ch->refund();
                         $refund_success = true;
                     } catch (Exception $e) {
                         $error_msg = $e->getMessage();
                     }
                 }
                 if ($refund_success == true) {
                     $psts->log_action($blog_id, sprintf(__('Subscription cancelled and a prorated (%1$s) refund of last payment completed by %2$s', 'psts'), $psts->format_currency(false, $refund), $current_user->display_name));
                     $success_msg = sprintf(__('Subscription cancelled and a prorated (%s) refund of last payment were successfully completed.', 'psts'), $psts->format_currency(false, $refund));
                     update_blog_option($blog_id, 'psts_stripe_canceled', 1);
                 } else {
                     $psts->log_action($blog_id, sprintf(__('Subscription cancelled, but prorated (%1$s) refund of last payment by %2$s returned an error: %3$s', 'psts'), $psts->format_currency(false, $refund), $current_user->display_name, $error_msg));
                     $error_msg = sprintf(__('Subscription cancelled, but prorated (%1$s) refund of last payment returned an error: %2$s', 'psts'), $psts->format_currency(false, $refund), $error_msg);
                     update_blog_option($blog_id, 'psts_stripe_canceled', 1);
                 }
                 break;
             case 'refund':
                 try {
                     $charge_object = Stripe_Charge::all(array("count" => 1, "customer" => $customer_id));
                     $charge_id = $charge_object->data[0]->id;
                     $ch = Stripe_Charge::retrieve($charge_id);
                     $ch->refund();
                     $psts->log_action($blog_id, sprintf(__('A full (%1$s) refund of last payment completed by %2$s The subscription was not cancelled.', 'psts'), $psts->format_currency(false, $refund), $current_user->display_name));
                     $success_msg = sprintf(__('A full (%s) refund of last payment was successfully completed. The subscription was not cancelled.', 'psts'), $psts->format_currency(false, $refund));
                     $psts->record_refund_transaction($blog_id, $charge_id, $refund);
                 } catch (Exception $e) {
                     $error_msg = $e->getMessage();
                     $psts->log_action($blog_id, sprintf(__('Attempt to issue a full (%1$s) refund of last payment by %2$s returned an error: %3$s', 'psts'), $psts->format_currency(false, $refund), $current_user->display_name, $error_msg));
                     $error_msg = sprintf(__('Attempt to issue a full (%1$s) refund of last payment returned an error: %2$s', 'psts'), $psts->format_currency(false, $refund), $error_msg);
                 }
                 break;
             case 'partial_refund':
                 try {
                     $charge_object = Stripe_Charge::all(array("count" => 1, "customer" => $customer_id));
                     $charge_id = $charge_object->data[0]->id;
                     $ch = Stripe_Charge::retrieve($charge_id);
                     $ch->refund(array("amount" => $refund_amount));
                     $psts->log_action($blog_id, sprintf(__('A partial (%1$s) refund of last payment completed by %2$s The subscription was not cancelled.', 'psts'), $psts->format_currency(false, $refund_value), $current_user->display_name));
                     $success_msg = sprintf(__('A partial (%s) refund of last payment was successfully completed. The subscription was not cancelled.', 'psts'), $psts->format_currency(false, $refund_value));
                     $psts->record_refund_transaction($blog_id, $charge_id, $refund);
                 } catch (Exception $e) {
                     $error_msg = $e->getMessage();
                     $psts->log_action($blog_id, sprintf(__('Attempt to issue a partial (%1$s) refund of last payment by %2$s returned an error: %3$s', 'psts'), $psts->format_currency(false, $refund_value), $current_user->display_name, $error_msg));
                     $error_msg = sprintf(__('Attempt to issue a partial (%1$s) refund of last payment returned an error: %2$s', 'psts'), $psts->format_currency(false, $refund_value), $error_msg);
                 }
                 break;
         }
     }
     //display resulting message
     if ($success_msg) {
         echo '<div class="updated fade"><p>' . $success_msg . '</p></div>';
     } else {
         if ($error_msg) {
             echo '<div class="error fade"><p>' . $error_msg . '</p></div>';
         }
     }
 }
 /**
  * Getting all the charges for the user
  * @param stripe key
  *
  * @return an array with the charges
  */
 public static function getCharges($key)
 {
     $out_charges = array();
     // telling stripe who we are
     Stripe::setApiKey($_ENV['STRIPE_SECRET_KEY']);
     // getting the charges
     // https://stripe.com/docs/api/php#charges
     $returned_object = Stripe_Charge::all();
     // extractin json (this is not the best approach)
     $charges = json_decode(strstr($returned_object, '{'), true);
     // getting relevant fields
     foreach ($charges['data'] as $charge) {
         // updating array
         /*
         id                      - string
         created                 - timestamp
         amount                  - non negative integer
         currency                - string, 3 letter ISO currency code
         paid                    - boolean
         captured                - boolean
         description             - string
         statement_description   - string
         failure_code            - string (see https://stripe.com/docs/api#errors for a list of codes)
         */
         $out_charges[$charge['id']] = array('created' => $charge['created'], 'amount' => $charge['amount'], 'currency' => $charge['currency'], 'paid' => $charge['paid'], 'captured' => $charge['captured'], 'description' => $charge['description'], 'statement_description' => $charge['statement_description'], 'failure_code' => $charge['failure_code']);
     }
     //foreach
     // returning object
     return $out_charges;
 }
Exemple #5
0
 /**
  * Get all customer charges
  * @param mixed $cus_attr
  * @param string $limit				Number of items to retrieve
  * @param string $ending_before		ID of the first element in the previous list
  * @param string $starting_after	ID of the last element in the previous list
  * @param mixed $created
  * @return boolean
  */
 public function getCharges($cus_attr = null, $limit = 10, $ending_before = null, $starting_after = null, $created = null)
 {
     try {
         if ($cus_attr) {
             $customer = new StripeCustomer($cus_attr);
             $customer_id = $customer->getCustomerAccount()->id;
         }
         $params = array_filter(array('created' => $created, 'customer' => $customer_id, 'limit' => $limit, 'ending_before' => $ending_before, 'starting_after' => $starting_after));
         return Stripe_Charge::all($params, $this->access_token);
     } catch (Exception $ex) {
         $this->log($ex);
         return false;
     }
 }
Exemple #6
0
 /**
  * Verified if user has paid through Stripe
  *
  * @since 1.0.0
  *
  * @param string $email address of user "logged" in
  * @return mixed Expiration date or subscriptions status or false if not paid
  */
 function leaky_paywall_has_user_paid($email = false, $blog_id = null)
 {
     $settings = get_leaky_paywall_settings();
     $paid = false;
     $canceled = false;
     $expired = false;
     $sites = array('');
     //Empty String for non-Multisite, so we cycle through "sites" one time with no $site set
     if (is_multisite_premium()) {
         if (is_null($blog_id)) {
             global $blog_id;
             if (!is_main_site($blog_id)) {
                 $sites = array('_all', '_' . $blog_id);
             } else {
                 $sites = array('_all', '_' . $blog_id, '');
             }
         } else {
             if (is_int($blog_id)) {
                 $sites = array('_' . $blog_id);
             } else {
                 if (empty($blog_id)) {
                     $sites = array('');
                 } else {
                     $sites = array($blog_id);
                 }
             }
         }
     }
     $mode = 'off' === $settings['test_mode'] ? 'live' : 'test';
     if (empty($email)) {
         $user = wp_get_current_user();
     } else {
         if (is_email($email)) {
             $user = get_user_by('email', $email);
         } else {
             return false;
         }
     }
     foreach ($sites as $site) {
         $subscriber_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, true);
         $expires = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_expires' . $site, true);
         $payment_gateway = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true);
         $payment_status = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_status' . $site, true);
         $plan = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_plan' . $site, true);
         if (!$paid) {
             if ('stripe' === $payment_gateway) {
                 if (!class_exists('Stripe')) {
                     require_once LEAKY_PAYWALL_PATH . 'include/stripe/lib/Stripe.php';
                 }
                 if ($mode == 'test') {
                     $secret_key = isset($settings['test_secret_key']) ? trim($settings['test_secret_key']) : '';
                 } else {
                     $secret_key = isset($settings['live_secret_key']) ? trim($settings['live_secret_key']) : '';
                 }
                 Stripe::setApiKey($secret_key);
                 try {
                     if (empty($subscriber_id)) {
                         switch ($payment_status) {
                             case 'Active':
                             case 'active':
                             case 'refunded':
                             case 'refund':
                                 if (empty($expires) || '0000-00-00 00:00:00' === $expires) {
                                     return 'unlimited';
                                 }
                                 if (strtotime($expires) < time()) {
                                     $expired = $expires;
                                 } else {
                                     $paid = true;
                                 }
                                 break;
                             case 'cancelled':
                             case 'canceled':
                                 if (empty($expires) || '0000-00-00 00:00:00' === $expires) {
                                     $expired = true;
                                 } else {
                                     $canceled = true;
                                 }
                             case 'reversed':
                             case 'buyer_complaint':
                             case 'denied':
                             case 'expired':
                             case 'failed':
                             case 'voided':
                             case 'deactivated':
                                 continue;
                                 break;
                         }
                     }
                     $cu = Stripe_Customer::retrieve($subscriber_id);
                     if (!empty($cu)) {
                         if (!empty($cu->deleted) && true === $cu->deleted) {
                             $canceled = true;
                         }
                     }
                     if (!empty($plan)) {
                         if (isset($cu->subscriptions)) {
                             $subscriptions = $cu->subscriptions->all('limit=1');
                             foreach ($subscriptions->data as $subscription) {
                                 if ('active' === $subscription->status) {
                                     return 'subscription';
                                 }
                             }
                         }
                     }
                     $ch = Stripe_Charge::all(array('count' => 1, 'customer' => $subscriber_id));
                     if (empty($expires) || '0000-00-00 00:00:00' === $expires) {
                         return 'unlimited';
                     } else {
                         if (strtotime($expires) < time()) {
                             if (true === $ch->data[0]->paid && false === $ch->data[0]->refunded) {
                                 $expired = $expires;
                             }
                         } else {
                             $paid = true;
                         }
                     }
                 } catch (Exception $e) {
                     $results = '<h1>' . sprintf(__('Error processing request: %s', 'issuem-leaky-paywall'), $e->getMessage()) . '</h1>';
                 }
             } else {
                 if ('paypal_standard' === $payment_gateway || 'paypal-standard' === $payment_gateway) {
                     if (empty($expires) || '0000-00-00 00:00:00' === $expires) {
                         return 'unlimited';
                     }
                     if (!empty($plan) && 'active' == $payment_status) {
                         return 'subscription';
                     }
                     switch ($payment_status) {
                         case 'active':
                         case 'refunded':
                         case 'refund':
                             if (strtotime($expires) < time()) {
                                 $expired = $expires;
                             } else {
                                 $paid = true;
                             }
                             break;
                         case 'cancelled':
                         case 'canceled':
                             $canceled = true;
                         case 'reversed':
                         case 'buyer_complaint':
                         case 'denied':
                         case 'expired':
                         case 'failed':
                         case 'voided':
                         case 'deactivated':
                             continue;
                             break;
                     }
                 } else {
                     if ('manual' === $payment_gateway) {
                         switch ($payment_status) {
                             case 'Active':
                             case 'active':
                             case 'refunded':
                             case 'refund':
                                 if (empty($expires) || '0000-00-00 00:00:00' === $expires) {
                                     return 'unlimited';
                                 }
                                 if (strtotime($expires) < time()) {
                                     $expired = $expires;
                                 } else {
                                     $paid = true;
                                 }
                                 break;
                             case 'cancelled':
                             case 'canceled':
                                 if (empty($expires) || '0000-00-00 00:00:00' === $expires) {
                                     $expired = true;
                                 } else {
                                     $canceled = true;
                                 }
                             case 'reversed':
                             case 'buyer_complaint':
                             case 'denied':
                             case 'expired':
                             case 'failed':
                             case 'voided':
                             case 'deactivated':
                                 continue;
                                 break;
                         }
                     } else {
                         if ('free_registration' === $payment_gateway) {
                             switch ($payment_status) {
                                 case 'Active':
                                 case 'active':
                                 case 'refunded':
                                 case 'refund':
                                     if (empty($expires) || '0000-00-00 00:00:00' === $expires) {
                                         return 'unlimited';
                                     }
                                     if (strtotime($expires) < time()) {
                                         $expired = $expires;
                                     } else {
                                         $paid = true;
                                     }
                                     break;
                                 case 'cancelled':
                                 case 'canceled':
                                     if (empty($expires) || '0000-00-00 00:00:00' === $expires) {
                                         $expired = true;
                                     } else {
                                         $canceled = true;
                                     }
                                 case 'reversed':
                                 case 'buyer_complaint':
                                 case 'denied':
                                 case 'expired':
                                 case 'failed':
                                 case 'voided':
                                 case 'deactivated':
                                     continue;
                                     break;
                             }
                         } else {
                             $paid = apply_filters('leaky_paywall_has_user_paid', $paid, $payment_gateway, $payment_status, $subscriber_id, $plan, $expires, $user, $mode, $site);
                         }
                     }
                 }
             }
         }
     }
     if ($canceled) {
         return false;
     }
     if ($expired) {
         return false;
     }
     return $paid;
 }
 public function get_all_customer($customer, $num_charges = 10, $offset = 0)
 {
     try {
         $ch = Stripe_Charge::all(array('count' => $num_charges, 'offset' => $offset, 'customer' => $customer));
         $raw_data = array();
         foreach ($ch->data as $record) {
             $raw_data[] = $record;
         }
         if (count($raw_data) > 0) {
             return $raw_data;
         } else {
             return FALSE;
         }
     } catch (Exception $e) {
         $this->error = TRUE;
         $this->message = $e->getMessage();
         $this->code = $e->getCode();
         return FALSE;
     }
 }
Exemple #8
0
				</div>
			<?php 
    }
    ?>
			<div class="customer-interal-notes">
				<?php 
    echo stripslashes($customer['metadata']['Internal Notes']);
    ?>
			</div>
		</div>
	</header>

<?php 
} else {
    //no customer set
    $charges = Stripe_Charge::all(array("count" => 100));
}
?>



	<table class="table" id="charges">

		<thead>
			<tr>
				<th>Charge ID</th>
				<th>Date</th>
				<th class="paid-th">Status</th>
				<th class="amount-th">Total</th>
				<th>Description</th>
				<th class="fname-th">First Name</th>