Coder Social home page Coder Social logo

stripebundle's Introduction

StripeBundle

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

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:

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.

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

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

If you want to do it manually you have a twig extension to get the stripe_publishable_key

    <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

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

stripebundle's People

Contributors

leobenoist avatar freddyhaddad avatar lemoinem avatar jmoughon avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.