Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stripe API #255

Open
ReeceMed opened this issue Dec 11, 2017 · 0 comments
Open

Stripe API #255

ReeceMed opened this issue Dec 11, 2017 · 0 comments

Comments

@ReeceMed
Copy link

ReeceMed commented Dec 11, 2017

Working with examples using stripe API, i have tried multiple different methods but can not seem to find a way of the report running.

Following the tutorial, i have created reports>my-reports>payments.php which looks like this based off of the stripe examples on their website https://stripe.com/docs/recipes/generating-custom-reports

//My Payments Report
//This connects to the Stripe Payments api and shows a list of charges
//VARIABLE: { name: "count", display: "Number of Charges" }

// If you're using Composer, use Composer's autoload
require __DIR__ . '/vendor/autoload.php';

// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey('StripeTestCodeAPIKEY');

if($count > 100 || $count < 1) throw new Exception("Number of Charges must be between 1 and 100");


// Retrieve a list of 50 most recent charges
$charges = \Stripe\Charge::all(array(
             'limit' => 50
           ));

// Loop through each charge
foreach ($charges->data as $charge) {

    // Get the required charge information and assign to variables
    $id = $charge->id;
    $description = $charge->description;
    $created = gmdate('Y-m-d H:i', $charge->created); // Format the time
    $amount = $charge->amount/100; // Convert amount from cents to dollars
    $currency = $charge->currency;

$rows = array();
foreach($charges as $charge) {
    $rows[] = array(
        'Charge Id'=>$charge->id,
        'Amount'=>number_format($charge->amount/100,2),
        'Date'=>date('Y-m-d',$charge->created)
    );
}

echo json_encode($rows);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant