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

List all plans #194

Open
Ezyweb-uk opened this issue Nov 10, 2020 · 1 comment
Open

List all plans #194

Ezyweb-uk opened this issue Nov 10, 2020 · 1 comment

Comments

@Ezyweb-uk
Copy link

Ezyweb-uk commented Nov 10, 2020

I've tested the listPlans() request and by default a maximum of 10 plans are returned. To return more plans I need to pass the parameter array('limit' => 100) but I've not been able to make this work.

Even if I add the parameter in Gateway.php as follows the parameter is not logged in Stripe:

    public function listPlans(array $parameters = array())
    {
        $parameters['limit'] = 100;
        return $this->createRequest('\Omnipay\Stripe\Message\ListPlansRequest', $parameters);
    }

But it does work if I use the stripe-php library

UPDATE: I've tried adding the following function to omnipay\stripe\src\Message\ListPlansRequest.php

public function setLimit($limit)
{
    return $this->setParameter('limit', $limit);
}

And changed my code to:

$request = $this->gateway->listPlans();
$request->setLimit('100');
$data = $request->getData();
$response = $request->sendData($data);

But still only 10 plans returned and the limit parameter is not logged as received in the Stripe request GET logs.

@Ezyweb-uk
Copy link
Author

The Stripe listPlans function is a GET request to https://api.stripe.com/v1/plans so the limit parameter needs to be in a query string like https://api.stripe.com/v1/plans?limit=3

I was hoping that Omnipay gateway logic, knowing that ListPlansRequest HttpMethod is 'GET', would add any parameters set to a query string in the CURLOPT_URL. So I tried the following code in my project:
$request = $this->gateway->listPlans(array('limit' => 100))->send();
and
$request = $this->gateway->listPlans()->initialize(array('setLimit' => 100))->send();
But neither applied the limit parameter.

So I added the following class methods to ListPlansRequest:

    public function getLimit()
    {
        return $this->getParameter('limit');
    }

    public function setLimit($limit)
    {
        return $this->setParameter('limit', $limit);
    }

And extended method get EndPoint:

    public function getEndpoint()
    {
        $query = '';

        $limit = (int)$this->getLimit();

        if($limit > 0) $query = '?' . http_build_query(array('limit' => $limit));

        return $this->endpoint.'/plans' . $query;
    }

And the following code in my project at last returned all 21 subscription plans:

$request = $this->gateway->listPlans(array('limit' => 100))->send();

Unless there's another way to pass a parameter to the GET request, it would be good if omnipay-stripe could be extended to accept the limit parameter in the listPlans request either as above or by some other method.

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