2017 © Pedro PelĂĄez
 

symfony-bundle stripe-bundle

Symfony 2 StripeBundle, a wrapper for Stripe Api

image

wemakecustom/stripe-bundle

Symfony 2 StripeBundle, a wrapper for Stripe Api

  • Saturday, November 12, 2016
  • by LeoBenoist
  • Repository
  • 6 Watchers
  • 7 Stars
  • 12,249 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 11 Forks
  • 1 Open issues
  • 4 Versions
  • 2 % Grown

The README.md

StripeBundle

Provides a simple Symfony 2 Bundle to Wrap the Stripe PHP SDK - https://github.com/stripe/stripe-php, (*1)

Installation

composer.json


{ "require": { "wemakecustom/stripe-bundle": "dev-master" } }

app/AppKernel.php


public function registerBundles() { $bundles = array( // ... new WMC\StripeBundle\WMCStripeBundle(), ); }

Configuration

Edit your symfony config.yml file and add, at a minimum, the following lines:, (*2)

wmc_stripe:
    api_secret_key:      stripe_secret_key
    api_publishable_key: stripe_publishable_key

Utilisation

Authentification

In Stripe you have two form of authentication. The one by your server and the one by your client., (*3)

To authenticate your server with the stripe secret key


$this->container->get('wmc_stripe.stripe')->auth(); // Instead of : Stripe::setApiKey("sk_somekey");

To authenticate your client with the stripe publishable key

Include all js at once in twig, (*4)


{% include "WMCStripeBundle::stripe.js.html.twig" %}

If you want to do it manually you have a twig extension to get the stripe_publishable_key, (*5)


<script type="text/javascript">Stripe.setPublishableKey('{{stripe_publishable_key}}');</script>

Example

If you want to do a basic card submission https://stripe.com/docs/tutorials/forms https://stripe.com/docs/tutorials/charges#saving-credit-card-details-for-later, (*6)

Basic saving of clients (card details), controller and a view :


public function newPaymentMethodAction(Request $request) { $this->container->get('wmc_stripe.stripe')->auth(); $form = $this->createForm(new CardFormType()); $formHandler = new CardFormHandler($form, $request, $stripeClientDescription); if($formHandler->process()){ //Persist flush the customerId somewhere $stripeCustomerId = $formHandler->getCustomer()->id; } return array('form' => $form->createView()); }

{% extends "::base.html.twig" %} {% block content %} {{ form_start(form) }} {{ form_errors(form) }} {{ form_widget(form) }} <button type="submit">Submit</button> {{ form_end(form) }} {% endblock %} {% block foot_script %} {{ parent() }} {% include "WMCStripeBundle::stripe.js.html.twig" %} {% endblock %}

Charge a client

            \Stripe\Charge::create(array(
                    "amount" => round($price * 100),
                    "currency" => "usd",
                    "customer" => $customerId)
            );

TODO:

  • Declare Form type and Handler as services

The Versions

12/11 2016

dev-master

9999999-dev http://www.wemakecustom.com

Symfony 2 StripeBundle, a wrapper for Stripe Api

  Sources   Download

MIT

The Requires

 

symfony2 bundle stripe

20/08 2015

v0.3

0.3.0.0 http://www.wemakecustom.com

Symfony 2 StripeBundle, a wrapper for Stripe Api

  Sources   Download

MIT

The Requires

 

symfony2 bundle stripe

15/07 2015

v0.2

0.2.0.0 http://www.wemakecustom.com

Symfony 2 StripeBundle, a wrapper for Stripe Api

  Sources   Download

MIT

The Requires

 

symfony2 bundle stripe

15/07 2015

v0.1

0.1.0.0 http://www.wemakecustom.com

Symfony 2 StripeBundle, a wrapper for Stripe Api

  Sources   Download

MIT

The Requires

 

symfony2 bundle stripe