Skip to content

Instantly share code, notes, and snippets.

@teohhanhui
Last active June 26, 2019 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teohhanhui/1c2ac1d27f948993bf8c4209a8808f39 to your computer and use it in GitHub Desktop.
Save teohhanhui/1c2ac1d27f948993bf8c4209a8808f39 to your computer and use it in GitHub Desktop.
Using Omnipay with Sylius (example using Stripe)
{
...
"require": {
...
"omnipay/common": "^3.0@beta",
"omnipay/stripe": "^3.0@dev",
"payum/omnipay-v3-bridge": "^1.0",
...
},
...
}
app:
form:
gateway_configuration:
omnipay_stripe:
api_key: API key
payum_gateway_factory:
omnipay_stripe: Stripe (via Omnipay)
<?php
declare(strict_types=1);
namespace AppBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
final class OmnipayStripeGatewayConfigurationType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
parent::buildForm($builder, $options);
$builder
->add('apiKey', TextType::class, [
'label' => 'app.form.gateway_configuration.omnipay_stripe.api_key',
'constraints' => [
new NotBlank([
'message' => 'app.gateway_config.omnipay_stripe.api_key.not_blank',
'groups' => 'sylius',
]),
],
])
->add('type', HiddenType::class, [
'data' => 'Stripe',
])
;
}
}
services:
AppBundle\Form\Type\OmnipayStripeGatewayConfigurationType:
tags:
- name: sylius.gateway_configuration_type
type: omnipay
label: app.payum_gateway_factory.omnipay_stripe
app:
gateway_config:
omnipay_stripe:
api_key:
not_blank: Please enter Stripe API key.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment