Giter Club home page Giter Club logo

stripe-bundle's Introduction

flosch/stripe-bundle

A symfony >= 3 integration for the Stripe PHP SDK

⚠️ IMPORTANT: Before you use this bundle... ⚠️

Some (rather big!) changes are coming quite soon affecting online payment solutions in Europe, impacting the Stripe APIs used by this bundle. Read this issue carefully before using this bundle.

Description

This bundle allow you to manipulate the stripe SDK as a Symfony service, Plus some helpers to use different Stripe API notions such as Stripe Connect or the Subscriptions API.

NOTE : The master branch, and 1.. releases target Symfony 3. If you are using Symfony 4, please use the 2.0.0 branch and the 2.. releases of this bundle.

Installation

To install this bundle, run the command below and you will get the latest version from [Packagist][3].

composer require flosch/stripe-bundle

Load required bundles in AppKernel.php:

// app/AppKernel.php
public function registerBundles()
{
  $bundles = array(
    // [...]
    new Flosch\Bundle\StripeBundle\FloschStripeBundle()
  );
}

And set-up the required configuration

# app/config/config.yml
flosch_stripe:
    stripe_api_key: "%stripe_api_key%" # The Stripe API key can be added as a symfony parameter

Usage

Then, it is possible to use this service from inside a controller

$stripeClient = $this->get('flosch.stripe.client');

The StripeClient php class extends the default Stripe PHP SDK class, allowing you to do anything that this SDK can do. Plus, it will automatically be authenticated with your Stripe API Key, which you do not have to worry about at all.

Extends the client

I will always be open to PR in order to update this project, However if you wish to add your own custom helpers, you can easily extend it yourself, for instance :

<?php // src/YourNamespace/YourProject/Stripe/StripeClient.php

namespace YourNamespace\YourProject\Stripe;

use Flosch\Bundle\StripeBundle\Stripe\StripeClient as BaseStripeClient;

class StripeClient extends BaseStripeClient
{
    public function __construct($stripeApiKey = '')
    {
        parent::__construct($stripeApiKey);

        return $this;
    }

    public function myOwnMethod()
    {
        // Do what you want here...
    }
}

Then register your extension as a service, and use it.

http://symfony.com/doc/current/service_container/3.3-di-changes.html

services:
    YourNamespace\YourProject\Stripe\StripeClient:
        autowire: true
        autoconfigure: true
        lazy: true

    my.stripe.client:
        alias: YourNamespace\YourProject\Stripe\StripeClient
public function indexAction()
{
    // Retrieve it from the container with the old-school getter
    $stripeClient = $this->get('my.stripe.client');
}

public function indexAction(\YourNamespace\YourProject\Stripe\StripeClient $stripeClient)
{
    // Or inject it in your controllers if you use autowiring
    // Then you're ready to go...
}

Helpers

The StripeClient currently offers four helper methods :

Retrieve a Coupon by its ID
/**
 * $planId (string)         : The existing Coupon ID (the one you define in the Stripe dashboard)
 */
$coupon = $stripeClient->retrieveCoupon($planId);
Retrieve a Plan by its ID
/**
 * $planId (string)         : The existing Plan ID (the one you define in the Stripe dashboard)
 */
$plan = $stripeClient->retrievePlan($planId);
Retrieve a Customer by its ID
/**
 * $customerId (string)         : The existing Customer ID
 */
$customer = $stripeClient->retrieveCustomer($customerId);
Retrieve a Charge by its ID
/**
 * $chargeId (string)         : The existing Charge ID
 */
$charge = $stripeClient->retrieveCharge($chargeId);
Create a new customer
/**
 * $paymentToken (string)   : The payment token obtained using the Stripe.js library
 * $customerEmail (string)  : The customer e-mail address
 */
$stripeClient->createCustomer($paymentToken, $customerEmail);
Create and subscribe a new customer to an existing plan
/**
 * $planId (string)         : The existing Plan ID (the one you define in the Stripe dashboard)
 * $paymentToken (string)   : The payment token obtained using the Stripe.js library
 * $customerEmail (string)  : The customer e-mail address
 * $couponId (string|null)  : An optional coupon ID
 */
$stripeClient->subscribeCustomerToPlan($planId, $paymentToken, $customerEmail, $couponId);
Subscribe an existing customer to an existing plan
/**
 * $customerId (string)     : The existing Customer ID
 * $planId (string)         : The existing Plan ID (the one you define in the Stripe dashboard)
 * $parameters (array)      : An optional array of additional parameters
 */
$stripeClient->subscribeExistingCustomerToPlan($customerId, $planId, [
    'coupon'        => 'TEST',
    'tax_percent'   => 19.6
]);
Create a charge (to a platform, or a connected Stripe account)
/**
 * $chargeAmount (int)              : The charge amount in cents, for instance 1000 for 10.00 (of the currency)
 * $chargeCurrency (string)         : The charge currency (for instance, "eur")
 * $paymentToken (string)           : The payment token obtained using the Stripe.js library
 * $stripeAccountId (string|null)   : (optional) The connected string account ID, default null (--> charge to the platform)
 * $applicationFee (int)            : The amount of the application fee (in cents), default to 0
 * $chargeDescription (string)      : (optional) The charge description for the customer
 */
$stripeClient->createCharge($chargeAmount, $chargeCurrency, $paymentToken, $stripeAccountId, $applicationFee, $chargeDescription);
Refund a Charge
/**
 * $chargeId (string)           : The Stripe charge ID (returned by Stripe when you create a charge)
 * $refundAmount (int)          : The charge amount in cents (if null, the whole charge amount will be refunded)
 * $metadata (array)            : additional informations about the refund, default []
 * $reason (string)             : The reason of the refund, either "requested_by_customer", "duplicate" or "fraudulent"
 * $refundApplicationFee (bool) : Wether the application_fee should be refunded aswell, default true
 * $reverseTransfer (bool)      : Wether the transfer should be reversed (when using Stripe Connect "destination" parameter on charge creation), default false
 * $stripeAccountId (string)    : (optional) TheStripe account on which the charge has been made (Stripe Connect), default null (--> refund by the platform)
 */
$stripeClient->refundCharge($chargeId, $refundAmount, $metadata, $reason, $refundApplicationFee, $reverseTransfer, $stripeAccountId);

stripe-bundle's People

Contributors

flo-sch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

stripe-bundle's Issues

Can't install to Symfony 3.2

When I tried to install the bundle using composer, I received the following output at the console:

composer require flosch/stripe-bundle Using version ^0.1.9 for flosch/stripe-bundle ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Problem 1 - Can only install one of: stripe/stripe-php[v3.23.0, v5.5.0]. - Can only install one of: stripe/stripe-php[v5.5.0, v3.23.0]. - Can only install one of: stripe/stripe-php[v3.23.0, v5.5.0]. - flosch/stripe-bundle 0.1.9 requires stripe/stripe-php ~3.23 -> satisfiable by stripe/stripe-php[v3.23.0]. - Installation request for flosch/stripe-bundle ^0.1.9 -> satisfiable by flosch/stripe-bundle[0.1.9]. - Installation request for stripe/stripe-php (locked at v5.5.0) -> satisfiable by stripe/stripe-php[v5.5.0]. Installation failed, reverting ./composer.json to its original content.

How can I solve this issue?

Can't install Symfony 4

Hi !
(and thank you for this bundle)

Seems that the bundle is not yet compatible with Symfony 4

flosch/stripe-bundle 0.1.9 requires symfony/symfony ~3.0 -> satisfiable by symfony/symfony[3.0.x-dev, 3.1.x-dev, 3.2.x-dev, 3.3.x-dev, 3.4.x-dev, v3.0.0, v3.0.0-BETA1, v3.0.1, v3.0.2, v3.0.3, v3.0.4, v3.0.5, v3.0.6, v3.0.7, v3.0.8, v3.0.9, v3.1.0, v3.1.0-BETA1, v3.1.0-RC1, v3.1.1, v3.1.10, v3.1.2, v3.1.3, v3.1.4, v3.1.5, v3.1.6, v3.1.7, v3.1.8, v3.1.9, v3.2.0, v3.2.0-BETA1, v3.2.0-RC1, v3.2.0-RC2, v3.2.1, v3.2.10, v3.2.11, v3.2.12, v3.2.13, v3.2.14, v3.2.2, v3.2.3, v3.2.4, v3.2.5, v3.2.6, v3.2.7, v3.2.8, v3.2.9, v3.3.0, v3.3.0-BETA1, v3.3.0-RC1, v3.3.1, v3.3.10, v3.3.11, v3.3.12, v3.3.13, v3.3.14, v3.3.2, v3.3.3, v3.3.4, v3.3.5, v3.3.6, v3.3.7, v3.3.8, v3.3.9, v3.4.0, v3.4.0-BETA1, v3.4.0-BETA2, v3.4.0-BETA3, v3.4.0-BETA4, v3.4.0-RC1, v3.4.0-RC2, v3.4.1] but these conflict with your requirements or minimum-stability.

ProxyManager dependency issue

Seems there's an issue now relying on ProxyManager?
After running composer require flosch/stripe-bundle

PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 2 passed to ProxyManager\Generator\Util\ProxiedMethodReturnExpression::generate() must be an instance of ProxyManager\Generator\Util\ReflectionMethod, instance of Zend\Code\Reflection\MethodReflection given,

$stripeApiKeyhas no type-hint

Hey,

I working on a symfony 4 project and when i wanted to integrate the bundle. when i try to create a customer i have this

Uncaught PHP Exception Symfony\Component\DependencyInjection\Exception\RuntimeException: "Cannot resolve argument $stripeClient of "App\Controller\User\RegisterPaymentMethodController()": Cannot autowire service "Flosch\Bundle\StripeBundle\Stripe\StripeClient": argument "$stripeApiKey" of method "__construct()" has no type-hint, you should configure its value explicitly." at /Users/simonackermann/Sites/courses/symfony/champeryNb/var/cache/dev/ContainerOspQEUr/getStripeClientService.php line 9

I realy don't know what to do.
here is all my code;
https://github.com/simonackermann/private-rent/tree/feature/creditCardPayment

Thanks in advanc for the help

⚠️ about this bundle ⚠️

I originally developed this bundle to ease the Stripe integration in some projects I was working on.
It still work today with specific versions of the Stripe PHP API and Symfony.

However, I no longer have the time to maintain it at the moment, and especially not support the new versions of the Stripe API, not all by myself at least.

If anyone is interested in maintaining such a bundle / making, I would gladly accept some help, we can discuss for instance the publications details on packagist etc.

Otherwise, and especially nowadays, you may consider stop using this bundle, especially under the light of important changes regarding payment regulations in Europe and what it means for Stripe integrations

More informations:

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.