PHP code example of pimcore / payment-provider-paypal-smart-payment-button

1. Go to this page and download the library: Download pimcore/payment-provider-paypal-smart-payment-button library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pimcore / payment-provider-paypal-smart-payment-button example snippets



    
        /** @var \Pimcore\Bundle\EcommerceFrameworkBundle\PaymentManager\Payment\PayPalSmartPaymentButton $payment */
     


//in your payment controller, e.g. startPaymentAction

public function startPaymentAction() {
    
    // ... some other stuff
    
        
        $paymentConfig = new AbstractRequest($config);
        
        $response = $checkoutManager->startOrderPaymentWithPaymentProvider($paymentConfig);
    
    
    $checkoutManager = Factory::getInstance()->getCheckoutManager($cart);
    $paymentInformation = $checkoutManager->initOrderPayment();
    $payment = $checkoutManager->getPayment();
    
    $config = [
        'return_url' => $returnUrl,
        'cancel_url' => $cancelUrl . 'payment?error=cancel',
        'OrderDescription' => 'My Order ' . $order->getOrdernumber() . ' at pimcore.org',
        'InternalPaymentId' => $paymentInformation->getInternalPaymentId()
    ];
    
    $paymentConfig = new AbstractRequest($config);
    
    $response = $checkoutManager->startOrderPaymentWithPaymentProvider($paymentConfig);
    return new \Symfony\Component\HttpFoundation\JsonResponse($response->getJsonString(), 200, [], true);

} 



public function handleResponseAction() {

    // ... do some stuff 
    
    $checkoutManager = Factory::getInstance()->getCheckoutManager($cart);
    $params = array_merge($request->query->all(), $request->request->all());

    $order = $checkoutManager->handlePaymentResponseAndCommitOrderPayment($params);
    
    // optional to clear payment
    // if this call is necessary depends on payment provider and configuration.
    // its possible to execute this later (e.g. when shipment is done)
//  $payment = $checkoutManager->getPayment();
//  $paymentStatus = $payment->executeDebit();
//  $orderAgent = Factory::getInstance()->getOrderManager()->createOrderAgent($order);
//  $orderAgent->updatePayment($paymentStatus);    
    
    // ... check order state and redirect user to error page or order success page
    
} 
bash
php bin/console pimcore:bundle:enable PimcorePaymentProviderPayPalSmartPaymentButtonBundle
php bin/console pimcore:bundle:install PimcorePaymentProviderPayPalSmartPaymentButtonBundle