コード例 #1
0
ファイル: Invoice.php プロジェクト: autocar/laravel-billing
 /**
  * Gets info for an invoice.
  *
  * @return array|null
  */
 public function info()
 {
     if (!$this->id || !$this->stripe_customer) {
         return null;
     }
     if (!$this->stripe_invoice) {
         $this->stripe_invoice = Stripe_Invoice::retrieve($this->id);
         if ($this->stripe_customer->id != $this->stripe_invoice->customer) {
             return $this->stripe_invoice = null;
         }
     }
     if (!$this->stripe_invoice) {
         return null;
     }
     $discounts = array();
     if ($this->stripe_invoice->discount) {
         $discounts[] = array('coupon' => $this->stripe_invoice->discount->coupon->id, 'amount_off' => $this->stripe_invoice->discount->coupon->amount_off, 'percent_off' => $this->stripe_invoice->discount->coupon->percent_off, 'started_at' => date('Y-m-d H:i:s', $this->stripe_invoice->discount->start), 'ends_at' => $this->stripe_invoice->discount->end ? date('Y-m-d H:i:s', $this->stripe_invoice->discount->end) : null);
     }
     $items = array();
     foreach ($this->stripe_invoice->lines->data as $line) {
         $item = array('id' => $line->id, 'amount' => $line->amount, 'period_start' => null, 'period_end' => null, 'description' => $line->description, 'subscription_id' => 'subscription' == $line->type ? $line->id : $line->subscription, 'quantity' => $line->quantity);
         if ($line->period && $line->period->start) {
             $item['period_start'] = date('Y-m-d H:i:s', $line->period->start);
         }
         if ($line->period && $line->period->end) {
             $item['period_end'] = date('Y-m-d H:i:s', $line->period->end);
         }
         $items[] = $item;
     }
     return array('id' => $this->id, 'date' => date('Y-m-d H:i:s', $this->stripe_invoice->date), 'total' => $this->stripe_invoice->total, 'subtotal' => $this->stripe_invoice->subtotal, 'amount' => $this->stripe_invoice->amount_due, 'starting_balance' => $this->stripe_invoice->starting_balance, 'ending_balance' => $this->stripe_invoice->ending_balance, 'closed' => $this->stripe_invoice->closed, 'paid' => $this->stripe_invoice->paid, 'discounts' => $discounts, 'items' => $items);
 }
 public function add_payment_details($html, $details)
 {
     //echo '<pre>' . print_r( $details, true ) . '</pre>';
     if (!isset($details->invoice)) {
         return $html;
     }
     $invoice = \Stripe\Invoice::retrieve($details->invoice);
     $interval = $invoice->lines->data[0]->plan->interval;
     $interval_count = $invoice->lines->data[0]->plan->interval_count;
     $amount = $invoice->lines->data[0]->plan->amount;
     $starting_balance = $invoice->starting_balance;
     $html = '<div class="sc-payment-details-wrap">' . "\n";
     $html .= '<p>' . __('Congratulations. Your payment went through!', 'sc_sub') . '</p>' . "\n";
     $html .= '<p>' . "\n";
     if (!empty($details->description)) {
         $html .= __("Here's what you purchased:", 'sc_sub') . '<br/>' . "\n";
         $html .= stripslashes($details->description) . '<br/>' . "\n";
     }
     if (isset($_GET['store_name']) && !empty($_GET['store_name'])) {
         $html .= __('From: ', 'sc_sub') . stripslashes(stripslashes(urldecode($_GET['store_name']))) . '<br/>' . "\n";
     }
     $html .= '<br/>' . "\n";
     $html .= '<strong>' . __('Total Paid: ', 'sc_sub') . Stripe_Checkout_Misc::to_formatted_amount($details->amount, $details->currency) . ' ' . strtoupper($details->currency) . '</strong>' . "\n";
     $html .= '</p>' . "\n";
     $html .= '<p>';
     if ($starting_balance > 0) {
         $html .= sprintf(__('You have been charged a one time fee of: %1$s %2$s', 'sc'), Stripe_Checkout_Misc::to_formatted_amount($starting_balance, $details->currency), strtoupper($details->currency)) . '<br>';
     }
     $html .= __('You will be charged ', 'sc_sub');
     $html .= Stripe_Checkout_Misc::to_formatted_amount($amount, $details->currency) . ' ' . strtoupper($details->currency);
     // For interval count of 1, use $1.00/month format.
     // For a count > 1, use $1.00 every 3 months format.
     if ($interval_count == 1) {
         $html .= '/' . $interval;
     } else {
         $html .= ' ' . __('every', 'sc_sub') . ' ' . $interval_count . ' ' . $interval . 's';
     }
     $html .= '</p>' . "\n";
     $html .= '<p>' . sprintf(__('Your transaction ID is: %s', 'sc_sub'), $details->id) . '</p>';
     $html .= '</div>';
     return $html;
 }
コード例 #3
0
ファイル: StripeGateway.php プロジェクト: kyranb/cashier
 /**
  * Find an invoice by ID.
  *
  * @param  string  $id
  * @return \Laravel\Cashier\Invoice|null
  */
 public function findInvoice($id)
 {
     try {
         return new Invoice($this->billable, StripeInvoice::retrieve($id, $this->getStripeKey()));
     } catch (\Exception $e) {
         return null;
     }
 }
コード例 #4
0
 public function process_webhooks()
 {
     if (!isset($_GET['listener']) || strtolower($_GET['listener']) != 'stripe') {
         return;
     }
     // Ensure listener URL is not cached by W3TC
     if (!defined('DONOTCACHEPAGE')) {
         define('DONOTCACHEPAGE', true);
     }
     \Stripe\Stripe::setApiKey($this->secret_key);
     // retrieve the request's body and parse it as JSON
     $body = @file_get_contents('php://input');
     $event_json_id = json_decode($body);
     $expiration = '';
     // for extra security, retrieve from the Stripe API
     if (isset($event_json_id->id)) {
         $rcp_payments = new RCP_Payments();
         $event_id = $event_json_id->id;
         try {
             $event = \Stripe\Event::retrieve($event_id);
             $payment_event = $event->data->object;
             if (empty($payment_event->customer)) {
                 die('no customer attached');
             }
             // retrieve the customer who made this payment (only for subscriptions)
             $user = rcp_get_member_id_from_profile_id($payment_event->customer);
             if (empty($user)) {
                 // Grab the customer ID from the old meta keys
                 global $wpdb;
                 $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '_rcp_stripe_user_id' AND meta_value = %s LIMIT 1", $payment_event->customer));
             }
             if (empty($user)) {
                 die('no user ID found');
             }
             $member = new RCP_Member($user);
             // check to confirm this is a stripe subscriber
             if ($member) {
                 if (!$member->get_subscription_id()) {
                     die('no subscription ID for member');
                 }
                 if ($event->type == 'charge.succeeded' || $event->type == 'invoice.payment_succeeded') {
                     // setup payment data
                     $payment_data = array('date' => date_i18n('Y-m-d g:i:s', $event->created), 'payment_type' => 'Credit Card', 'user_id' => $member->ID, 'amount' => '', 'transaction_id' => '');
                     if ($event->type == 'charge.succeeded') {
                         // Successful one-time payment
                         if (empty($payment_event->invoice)) {
                             $payment_data['amount'] = $payment_event->amount / rcp_stripe_get_currency_multiplier();
                             $payment_data['transaction_id'] = $payment_event->id;
                             // Successful subscription payment
                         } else {
                             $invoice = \Stripe\Invoice::retrieve($payment_event->invoice);
                             $payment_data['amount'] = $invoice->amount_due / rcp_stripe_get_currency_multiplier();
                             $payment_data['transaction_id'] = $payment_event->id;
                         }
                         // Successful subscription paid made with account credit where no charge is created
                     } elseif ($event->type == 'invoice.payment_succeeded' && empty($payment_event->charge)) {
                         $payment_data['amount'] = $payment_event->amount_due / rcp_stripe_get_currency_multiplier();
                         $payment_data['transaction_id'] = $payment_event->id;
                         $invoice = $payment_event;
                     }
                     if (!empty($payment_data['transaction_id']) && !$rcp_payments->payment_exists($payment_data['transaction_id'])) {
                         if (!empty($invoice->subscription)) {
                             $customer = \Stripe\Customer::retrieve($member->get_payment_profile_id());
                             $subscription = $customer->subscriptions->retrieve($invoice->subscription);
                             if (!empty($subscription)) {
                                 $expiration = date('Y-m-d 23:59:59', $subscription->current_period_end);
                                 $member->set_recurring();
                             }
                             $member->set_merchant_subscription_id($subscription->id);
                         }
                         $member->renew($member->is_recurring(), 'active', $expiration);
                         // These must be retrieved after the status is set to active in order for upgrades to work properly
                         $payment_data['subscription'] = $member->get_subscription_name();
                         $payment_data['subscription_key'] = $member->get_subscription_key();
                         // record this payment if it hasn't been recorded yet
                         $rcp_payments->insert($payment_data);
                         do_action('rcp_stripe_charge_succeeded', $user, $payment_data);
                         die('rcp_stripe_charge_succeeded action fired successfully');
                     } else {
                         die('duplicate payment found');
                     }
                 }
                 // failed payment
                 if ($event->type == 'charge.failed') {
                     do_action('rcp_stripe_charge_failed', $invoice);
                     die('rcp_stripe_charge_failed action fired successfully');
                 }
                 // Cancelled / failed subscription
                 if ($event->type == 'customer.subscription.deleted') {
                     if (!$member->just_upgraded()) {
                         $member->set_status('cancelled');
                         die('member cancelled successfully');
                     }
                 }
                 do_action('rcp_stripe_' . $event->type, $payment_event);
             }
         } catch (Exception $e) {
             // something failed
             die('PHP exception: ' . $e->getMessage());
         }
         die('1');
     }
     die('no event ID found');
 }
コード例 #5
0
ファイル: Billable.php プロジェクト: yii2mod/yii2-cashier
 /**
  * Find an invoice by ID.
  *
  * @param string $id
  *
  * @return Invoice|null
  */
 public function findInvoice($id)
 {
     try {
         return new Invoice($this, StripeInvoice::retrieve($id, $this->getStripeKey()));
     } catch (Exception $e) {
     }
 }
コード例 #6
0
ファイル: hook.php プロジェクト: yodathedark/moltis-tickets
<?php

require_once '../config.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $postdata = @file_get_contents("php://input");
    $event = json_decode($postdata);
    if ($event->type == 'invoice.payment_succeeded') {
        $customer_id = $event->data->object->customer;
        $customer = \Stripe\Customer::retrieve($customer_id);
        $invoice = \Stripe\Invoice::retrieve($event->data->object->id);
        // This is where we'd normally e-mail the invoice, but we'll just write out the invoice to a file instead.
        $from = "From: Oscar Wilde";
        $to = "To: " . $customer->email;
        $subject = "Subject: You have made a payment for another month of Wilde quotes";
        $body = "You have made a new payment for \$" . $invoice->total / 100.0 . ":\n\n";
        foreach ($invoice->lines->data as &$line) {
            if ($line->type == 'subscription') {
                $body .= "Subscription - " . $line->plan->name . ": " . $line->amount . "\n";
            } else {
                if ($line->type == 'invoiceitem') {
                    $body .= "Additional -" . $line->description . ": " . $line->amount;
                }
            }
        }
        $email_file = fopen($customer->id . "-" . $invoice->date, 'a');
        $email = $from . "\n" . $to . "\n" . $subject . "\n" . $body;
        fwrite($email_file, $email);
    }
}
コード例 #7
0
ファイル: StripeInvoice.php プロジェクト: adrx/stripe-bundle
 /**
  * Retrieve stripe invoice object
  *
  * @param string $id Invoice StripeID
  *
  * @return \Stripe\Invoice
  */
 public function retrieve($id)
 {
     return StripeInvoiceApi::retrieve($id);
 }
コード例 #8
0
 *
 * @author     Shane Barron <*****@*****.**>
 * @author     Aaustin Barron <*****@*****.**>
 * @copyright  2015 SocialApparatus
 * @license    http://opensource.org/licenses/MIT MIT
 * @version    1
 * @link       http://socialapparatus.com
 */
namespace SocialApparatus;

denyDirect();
$invoice_number = pageArray(1);
$has_plan = false;
$table = NULL;
\Stripe\Stripe::setApiKey(EcommercePlugin::secretKey());
$lines = \Stripe\Invoice::retrieve($invoice_number)->lines->all(array('limit' => 5000));
echo "<h2 class='text-center'>";
echo "Invoice " . $invoice_number;
echo "</h2>";
foreach ($lines['data'] as $line) {
    $table .= "<tr>";
    $table .= "<td>";
    $table .= $line->id;
    $table .= "</td>";
    $table .= "<td>";
    if ($line->plan) {
        $has_plan = true;
        $plan = $line->plan;
        $plan_id = $plan->id;
        $plan_entity = getEntity($plan_id);
        $table .= $plan_entity->title;