Giter VIP home page Giter VIP logo

stripe-eccube-plugin's Introduction

Stripe for EC-CUBE4.2

EC-CUBE4でStripeでクレジットカード決済ができるプラグインのサンプルです。 非公式プラグインですのでご利用は自己責任でお願い致します。

インストールと有効化

ライブラリをインストール

composer require stripe/stripe-php

EC-CUBEの認証キーを設定している場合のライブラリのインストール方法

bin/console eccube:composer:require stripe/stripe-php

GitHubからプラグインをクローン

git clone [email protected]:kurozumi/stripe-eccube-plugin.git app/Plugin

プラグインのインストールと有効化

bin/console eccube:plugin:install --code Stripe4
bin/console eccube:plugin:enable --code Stripe4

シークレットキーと公開キーを設定

Stripeのアカウントを取得して管理画面でAPIキーを設定してください。

Shopping/index.twigにタグを追記

Shopping/index.twigの支払い方法の下に以下のタグを追記してください。

{{ include('@Stripe4/credit.twig', ignore_missing=true) }}

以上で設定は終了です。 お疲れさまでした。

あとは配送方法設定で取り扱う支払い方法にStripeを追加してあげてください。

決済テスト用クレジットカード

通常のクレジットカード番号

4242 4242 4242 4242

3Dセキュア認証が必要なクレジットカード番号

4000 0000 0000 3220

stripe-eccube-plugin's People

Contributors

kurozumi avatar masanishi avatar nanasess avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

stripe-eccube-plugin's Issues

カード情報削除機能を追加したい

会員の場合に利用できるカード情報保存機能ですが、ユーザーが削除したいと思っても現状では削除できません。
マイページあたりに削除できるページがあると良いな、と思いました。

保存したカードを利用できない

発生条件

会員ログイン後、購入処理の際にクレジットカードを保存し、購入処理を行う。

その後、保存したクレジットカードを利用して購入処理を行う際に以下のエラーが発生。

エラー内容

The provided PaymentMethod was previously used with a PaymentIntent without Customer attachment, shared with a connected account without Customer attachment, or was detached from a Customer. It may not be used again. To use a PaymentMethod multiple times, you must attach it to a Customer first.

原因

エラー内容から、カスタマーとの紐付けを決済前に行う必要がある様子。

明日、プルリク作成を行おうと思いますが、具体的には
PaymentController.php の以下部分を書き換えることで、動作的には対応できそうです。

if ($Order->getCustomer()) {
                    if ($Order->getCustomer()->getCreditCards()->count() > 0) {
                        $stripeCustomer = $Order->getCustomer()->getCreditCards()->first()->getStripeCustomerId();
                        $paymentIntentData['customer'] = $stripeCustomer;
                    } else {
                        if ($Order->getStripeSavingCard()) {
                            $stripeCustomer = Customer::create([
                                "email" => $Order->getCustomer()->getEmail()
                            ]);
                            logs('stripe')->info($stripeCustomer->status);
                            $paymentIntentData['customer'] = $stripeCustomer->id;
                        }
                    }
                }
if ($Order->getCustomer()) {
                    if ($Order->getCustomer()->getCreditCards()->count() > 0) {
                        $stripeCustomer = $Order->getCustomer()->getCreditCards()->first()->getStripeCustomerId();
                        $paymentIntentData['customer'] = $stripeCustomer;

                        if ($Order->getStripeSavingCard()) {
                            $paymentMethod = PaymentMethod::retrieve($paymentMethodId);
                            $paymentMethod = $paymentMethod->attach(['customer' => $stripeCustomer]);
                        }
                    } else {
                        if ($Order->getStripeSavingCard()) {
                            $stripeCustomer = Customer::create([
                                "email" => $Order->getCustomer()->getEmail()
                            ]);
                            logs('stripe')->info($stripeCustomer->status);
                            $paymentIntentData['customer'] = $stripeCustomer->id;

                            $paymentMethod = PaymentMethod::retrieve($paymentMethodId);
                            $paymentMethod = $paymentMethod->attach(['customer' => $stripeCustomer->id]);
                        }
                    }
                }

不要な仮決済が溜まっていく問題

購入手続きで確認まで行って決済を完了しない場合、仮決済が溜まっていくので
どこかのタイミングでこれらをキャンセルする処理が必要。

保存済みのクレジットカードが保存できてしまう

保存済みのクレジットカード番号を入力後「カード情報を保存する」をチェックして注文すると、
保存済みのクレジットカードが再度Stripeに登録できてしまう。

カード番号入力時に登録済みカードかどうかチェックする必要がある。

3Dセキュア認証の処理をサイト内で行いたい

3Dセキュア認証はStripeのページへ遷移するが、これだと途中でブラウザを閉じてしまう可能性があるので、
Stripeのドキュメント通りiframeを使ってサイト内で認証を行えるようにしたい。

支払い処理方法を変更する

確認画面遷移時にPaymentIntentを取得しているため購入完了前にStripeにデータが送信されてしまうので、
確認画面遷移時はPaymentMethodのみ生成して、購入完了時にPaymentIntentを生成するよう変更する。

不要な顧客データをStripeから削除

購入手続き時にクレカ情報保存にチェック入れて確認画面に進み、
購入完了せずに離脱するとStripeに不要な顧客データが残ってしまうのでどこかのタイミングで削除したい。

TeamエンティティをCreditCardエンティティに変更しようかな。。

クレカ情報と定期課金をTeamエンティティで管理しようと思ったけど、
TeamエンティティをCardエンティティに変更する。

ひとつのクレカで複数の定期課金と紐付けられるようにする。

エンティティはCreditCardにして、
CardTypeもCreditCardTypeに変更してわかりやすくしよう。

ゲスト購入の場合の失敗をReadmeに追加

こんにちは。

突然のIssueを失礼致します。

ローカルのテスト環境では、ec-cubeをDockerで立ち上げて、こちらのプラグインをインストールしました。

そして以下の流れだと上手くいきました:

  • ユーザー登録
  • 購入(Stripeのテスト用のカードを使って)
  • 「ご注文完了」画面まで確認できました(/shopping/complete

ただ、ゲスト購入の場合には、「ご注文完了」画面まで移動できず、エラーが出ます:

そのStack Traceは以下となります:

Symfony\Component\Debug\Exception\FatalThrowableError:
Call to a member function getCreditCards() on null

  at /var/www/html/app/Plugin/Stripe4/Controller/PaymentController.php:152
  at Plugin\Stripe4\Controller\PaymentController->payment(object(Request))
     (/var/www/html/vendor/symfony/http-kernel/HttpKernel.php:151)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 2)
     (/var/www/html/vendor/symfony/http-kernel/HttpKernel.php:68)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 2)
     (/var/www/html/vendor/symfony/framework-bundle/Controller/ControllerTrait.php:108)
  at Symfony\Bundle\FrameworkBundle\Controller\Controller->forward('Plugin\\Stripe4\\Controller\\PaymentController::payment', array('_forwarded' => object(ParameterBag), '_controller' => 'Plugin\\Stripe4\\Controller\\PaymentController::payment'), array())
     (Eccube/Controller/AbstractController.php:184)
  at Eccube\Controller\AbstractController->forwardToRoute('stripe_payment', array(), array())
     (Eccube/Controller/ShoppingController.php:752)
  at Eccube\Controller\ShoppingController->executeApply(object(CreditCard))
     (Eccube/Controller/ShoppingController.php:372)
  at Eccube\Controller\ShoppingController->checkout(object(Request))
     (/var/www/html/vendor/symfony/http-kernel/HttpKernel.php:151)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (/var/www/html/vendor/symfony/http-kernel/HttpKernel.php:68)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (/var/www/html/vendor/symfony/http-kernel/Kernel.php:200)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (/var/www/html/index.php:76)

その原因はこのページに書いてある通り:https://qiita.com/dev_belltzel/items/d1c3079c480aa98a9530
「 EC-CUBEに会員ログインしていない場合は、StripeのCustomerは作成しない。」

なので、README.mdに同じ内容を追加できますでしょうか。もしくはこちらでPRを作りましょうか。


Stripeを使うことができるのがとても嬉しいので、このプラグインの開発に感謝します。

(因みに、購入確認画面に

お支払方法
クレジットカード決済(¥0)

が表示されることに関係している可能性はありますでしょうか?フォークして調べてみましたが、残念ながらec-cubeとPHPの初心者ですので、問題を把握できませんでした。)

注文手続き画面でお届け先を変更できない

お届け先の変更、またはお届け先の追加を選択すると、注文手続き画面をリロードする結果となる。

発生条件

EC-CUBEインストール後にREADME.mdの手順でプラグインを設定した状態。

ゲスト、会員ともに発生

原因

下記のエラー処理まで進んでしまっている。

Stripe4/Form/Extension/CreditCardExtension.php

if (null === $order->getStripePaymentMethodId()) {
    $form->get('stripe_payment_method_id')->addError(new FormError(trans('エラーが発生しました')));
}

対応方法

POSTにredirect_toを持っているかどうかでチェックはできますが、あまり良い解決方法ではないのかなと思っています。

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.