简体   繁体   中英

How to configure Payum so it can handle PayPal standard payments (not express checkout payments)?

How to configure Payum for Symfony so it can handle PayPal standard payments (not express checkout payments); exactly same way a basic PayPal button would do?

The example provided in documentation is for Express Checkout only:

public function prepareAction()
{
    $gatewayName = 'paypal_express_checkout';

    $storage = $this->get('payum')->getStorage('FrontBundle\Entity\Payment');

    $payment = $storage->create();
    $payment->setNumber(uniqid());
    $payment->setCurrencyCode('CHF');
    $payment->setTotalAmount(100); // 1.00
    $payment->setDescription('A description');
    $payment->setClientId('anId');
    $payment->setClientEmail('foo@example.com');

    $storage->update($payment);

    $captureToken = $this->get('payum')->getTokenFactory()->createCaptureToken(
        $gatewayName,
        $payment,
        'done' // the route to redirect after capture
    );

    return $this->redirect($captureToken->getTargetUrl());
}

public function doneAction(Request $request)
{
    dump($request);
    $token = $this->get('payum')->getHttpRequestVerifier()->verify($request);

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

    // You can invalidate the token, so that the URL cannot be requested any more:
    // $this->get('payum')->getHttpRequestVerifier()->invalidate($token);

    // Once you have the token, you can get the payment entity from the storage directly.
    // $identity = $token->getDetails();
    // $payment = $this->get('payum')->getStorage($identity->getClass())->find($identity);

    // Or Payum can fetch the entity for you while executing a request (preferred).
    $gateway->execute($status = new GetHumanStatus($token));
    $payment = $status->getFirstModel();

    // UPDATE SUBSCRIPTION END DATE IN USER ENTITY

    $subscription_end_date = new \DateTime("now+ 365 day");
    $subscription_end_date_string = $subscription_end_date->format('Y-m-d H:i:s');

    $user = $this->get('security.token_storage')->getToken()->getUser();
    $user->setSubscriptionEndDate($subscription_end_date);
    $em = $this->getDoctrine()->getManager();
    $em->persist($user);
    $em->flush($user);

    return $this->render('FrontBundle:App:subscription_confirmation.html.twig', [
        'page_title' => 'Accompagnement, coaching de vie personnelle et professionnelle à Genève',
        'subscription_end_date' => $subscription_end_date_string,
    ]);

}

But my client wants his users are able to make payments without any PayPal account (PayPal Guest Checkout).

Ok mine worked now, you just need to set up the Solutiontype

Sole: Buyer can check out without creating a PayPal account. This is referred to as PayPal Account Optional.

Mark: Buyer must have a PayPal account to check out.

$payment['SOLUTIONTYPE'] = 'Sole';

Check out here: https://developer.paypal.com/docs/classic/api/merchant/SetExpressCheckout_API_Operation_NVP/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM