Search code examples
symfonypaypalpayum

Payum/paypal checkout : What to do after redirecting me to done action


I am trying to use the payum solution to integrate paypal checkout to my website.

Step 1 : Payment Page, with the validation trigger the redirection to paypal : OK Step 2 : User use his credentials to login and authorize the payment : OK

Step 3 : User is correctly redirecting to my doneAction, with a correct token. Token status is "captured" : OK

Step 4: I have no idea what to do next, to validate the payment. I understand I have to validate the payment, but how ?

Below, there is my doneAction based on payum doc :

public function doneAction(Request $request){
        $token = $this->get('payum.security.http_request_verifier')->verify($request);

        $gateway = $this->get('payum')->getGateway($token->getGatewayName());

        $gateway->execute($status = new GetHumanStatus($token));
        //die(dump($status->isCaptured()));
        $payment = $status->getFirstModel();

        if ($status->isCaptured()) {
             // What to do here
        }

        return new JsonResponse(array(
            'status' => $status->getValue(),
            'payment' => array(
                'total_amount' => $payment->getTotalAmount(),
                'currency_code' => $payment->getCurrencyCode(),
                'details' => $payment->getDetails(),
            ),
        ));
    }

Thanks for reading.


Solution

  • In general you have to put there your business logic, for example

    if you sell products, you have to mark order as paid and notify your delivery service to ship the products.

    if your customer paid for an account, you have to enable it.

    if your customer paid for e-book, you have to send a download link to him

    So it completely up to what to put there. If status is captured which is equal to purchased do your things. if it is something different, pending for example act according to that status. failed means user did not pay, so do not ship him anything.

    You dont have return a json, it could a redirect or html page with receipt etc