Skip to content

Instantly share code, notes, and snippets.

@crmpicco
Created July 9, 2018 07:55
Show Gist options
  • Save crmpicco/fe92bd26e2b9e511caef00ad8a5e1776 to your computer and use it in GitHub Desktop.
Save crmpicco/fe92bd26e2b9e511caef00ad8a5e1776 to your computer and use it in GitHub Desktop.
getBraintreeSubscriptions
/**
*
* @param string $filepath
* @return array
*/
private function getBraintreeSubscriptions(string $filepath) : array
{
// open the exported Braintree CSV file
$subscriptions = [];
if (false !== ($handle = fopen($filepath, 'r'))) {
$i = 0;
while (false !== ($data = fgetcsv($handle, null, ','))) {
++$i;
if (1 === $i) {
continue; // skip the first line (headings)
}
// @TODO unsure if we need all this information
$subscriptions[] = [
'subscriptionId' => $data[0],
'customerId' => $data[1],
'customerFirstName' => $data[2],
'customerLastName' => $data[3],
'paymentMethodToken' => $data[4],
'planId' => $data[5],
'planName' => $data[6],
'status' => $data[7],
'merchantAccount' => $data[8],
'descriptorName' => $data[9],
'descriptorPhone' => $data[10],
'descriptorURL' => $data[11],
'subscriptionPrice' => $data[12],
'subscriptionCurrency' => $data[13],
'trialPeriod' => $data[14],
'firstBillDate' => $data[15],
'currentBillingPeriod' => $data[16],
'paidThroughDate' => $data[17],
'nextBillDate' => $data[18],
'balanceCurrency' => $data[19],
'nextBillingPeriodAmount' => $data[20],
'numberTransactions' => $data[21],
'numberAddons' => $data[22],
'numberDiscounts' => $data[23],
'numberBillingCycles' => $data[24],
'customerEmail' => $data[25],
];
}
}
return $subscriptions;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment