Question

Im trying to use the Omnipay API with Stripe, but I can't pass in extra parameters such as "Name", "Metadata", or "Zip".

   // The token is grabbed from stripe JS
   $this->stripe_gateway = Omnipay::create('Stripe');

   $response = $this->stripe_gateway->purchase([
        'amount' => $amount,
        'currency' => 'usd',
        'name' => $name,
        'description' => $product->title,
        'zip_address' => $zip,
        'metadata' => [
            'name' => $name,
            'user_id' => $this->session->get('id')
        ],
        'token' => $stripeToken,
    ])->send();

I cant get anything to work, is this not built into the API?

Was it helpful?

Solution

Omnipay uses it's own parameter names, not Stripe's. That's because Omnipay tries to abstract most of the differences between the various payment gateways.

Right now, the omnipay/stripe package doesn't support sending some of those parameters (only amount, currency, description, and now metadata). You can see the supported parameters here:

https://github.com/omnipay/stripe/blob/master/src/Message/AuthorizeRequest.php

That said, you can still easily access the underlying Stripe request to add your own custom parameters:

$request = $this->stripe_gateway->purchase([
    'amount' => $amount,
    'token' => $stripeToken,
    'metadata' => ['foo' => 'bar'],
]);
$data = $request->getData();

$data['zip_address'] = '12345';
$data['another_custom_parameter'] = 'wow';
$response = $request->sendData($data);

Note that:

$data = $request->getData();
$response = $request->sendData($data);

is exactly the same as calling:

$response = $request->send();

Alternatively, you could create a pull request to add extra parameters to the Omnipay Stripe package. I just added the metadata parameter as an example of this:

https://github.com/omnipay/stripe/commit/99c82dc42c7c0b9ec58d8c4fb917f3dc5d1c23e2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top