Git Product home page Git Product logo

combodopayumstripe's Issues

Is it usefull to repeat the whole readme?

I was thinking the best thing to do where to define that there is two types of examples in the main readme, and then point to two others readme in each example that would explain their specifications.

Originally posted by @bruno-ds in #9

There is no need of a webhook

As I can see in the code you have given directly the 'done' route to stripe; by doing that, once the payment is done, he doesn't go back through your gateway.

Here is the original way :

// src/Action/Api/ObtainTokenAction.php
private function obtainSession(ObtainToken $request, ArrayObject $model): Session
{
    Stripe::setApiKey($this->keys->getSecretKey());
    $session = Session::create(
        [
            'success_url'           => $request->getToken()->getAfterUrl(),
            'cancel_url'            => $request->getToken()->getAfterUrl(),
            'payment_method_types'  => ['card'],
            'submit_type'           => Session::SUBMIT_TYPE_PAY,
            'line_items'            => $model['line_items'],
            'payment_intent_data'   => [
                'metadata'              => $model['metadata'] ?? ['payment_id' => $model['id']],
            ],
            'client_reference_id'   => $request->getToken()->getHash(),
        ]
    );

    return $session;
}

By using the $request->getToken()->getTargetUrl() method you can get the capture url in order to send the user to this route after the payment.

Here is how I propose to do :

// src/Action/Api/ObtainTokenAction.php
private function obtainSession(ObtainToken $request, ArrayObject $model): Session
{
    Stripe::setApiKey($this->keys->getSecretKey());
    $session = Session::create(
        [
            'success_url'           => $request->getToken()->getTargetUrl() . '?status=success',
            'cancel_url'            => $request->getToken()->getTargetUrl() . '?status=canceled',
            'payment_method_types'  => ['card'],
            'submit_type'           => Session::SUBMIT_TYPE_PAY,
            'line_items'            => $model['line_items'],
            'payment_intent_data'   => [
                'metadata'              => $model['metadata'] ?? ['payment_id' => $model['id']],
            ],
            'client_reference_id'   => $request->getToken()->getHash(),
        ]
    );

    return $session;
}
// src/Action/CaptureAction.php
public function execute($request)
{
    RequestNotSupportedException::assertSupports($this, $request);
    $model = ArrayObject::ensureArrayObject($request->getModel());
    $getHttpRequest = new GetHttpRequest();
    $this->gateway->execute($getHttpRequest);
    if ($getHttpRequest->method == 'GET' && isset($getHttpRequest->query['status'])) {
        // @TODO Check payment status
        return;
    }

    if ($model['status']) {
        return;
    }

    if ($model['customer']) {
        return;
    }

    $obtainToken = new ObtainToken($request->getToken());
    $obtainToken->setModel($model);

    $this->gateway->execute($obtainToken);
}

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.