Skip to content

Instantly share code, notes, and snippets.

@flexgrip
Last active August 30, 2016 00:04
Show Gist options
  • Save flexgrip/0880c5b6c2ebd9a4a8e60d2b325bb95e to your computer and use it in GitHub Desktop.
Save flexgrip/0880c5b6c2ebd9a4a8e60d2b325bb95e to your computer and use it in GitHub Desktop.
StripePullByDate.php
while ($charges['has_more']) {
$charges = $stripe->getChargesByDate($start_date, $starting_after);
foreach($charges["data"] as $charge) {
// DEBUG
Log::info($charges['has_more']);
// Reset the data for the pager. Have to do this first in case we skip a dirty record.
$starting_after = $charge['id'];
$crm_id = $charge['customer'];
$amount = $charge['amount'] / 100;
$created_at = $charge['created'];
if(!$charge['customer'] || $charge['status'] == "failed" || $charge['status'] == "pending") {
Log::info("Starting after: " . $charge['id']);
//Log::info("No customer attached to this stripe charge. Aborting.");
//continue;
} // If there's no customer bound to the charge, skip it.
elseif(!$amount || !$crm_id || !$created_at) {
Log::error($this->date->toDateString() . ' could not process order: ' . json_encode($charge));
} else {
$payment = new Payment();
$payment->crm_id = $crm_id;
$payment->amount = $amount;
$payment->created_at = $created_at;
$payment->user_id = $this->user->id;
$payment->td_db = $this->user->td_db;
$payment->save();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment