Jump to content

Recommended Posts

Hello there!

I have some trouble these three last days with an addon development. 
My shop will be able to manage recurring payment (subscription) with SDD and debit card.
For this reason I bought 2 addons

  • Atos Worldline SIPS 
  • A subscription addon called pm_subscription.

This last module doesn't manage Worldline payment so I need to implement my own payment method in this addon.
For this, I have to create a <form> which send to an external Worldline link (a wallet configuration page) the customer, and the seller bank  information.
The main goal here is to let the customer be redirected on the Worldline link which requests POST information (said before).

So I tried to create a <form> on the right .tpl:

<form id="enablePayment" action="{url entity='module' name='pm_subscription' controller='redirectPayment'}" method="post">
    <input type="hidden" name="subid" value="{$subscriber->id|intval}" />
    <input type="submit" value="Configurer le paiement" name="enablePayment" rel="nofollow" class="btn btn-primary" title="Configurer paiement" data-id-			   subscriber="{$subscriber->id|intval}"/>
</form>

As you can see, I redirect the action to a front module controller that I created:

class pm_subscriptionRedirectPaymentModuleFrontController extends ModuleFrontController {
    
    public function postProcess() {
        
        // Include payments modules
        include(_PS_MODULE_DIR_.'pm_subscription'.DIRECTORY_SEPARATOR.'models'
                .DIRECTORY_SEPARATOR.'payment_modules'.DIRECTORY_SEPARATOR.'SubPaymentModuleWorldline.php');
        include(_PS_MODULE_DIR_.'pm_subscription'.DIRECTORY_SEPARATOR.'models'
                .DIRECTORY_SEPARATOR.'payment_modules'.DIRECTORY_SEPARATOR.'SubPaymentModuleSEPA.php');
        
        if (isset($_POST['subid'])) {
            
            // @TODO vérifier subid
            $subid = pSQL($_POST['subid']);
            
            // Récupérer méthode de paiement choisie
            $row = self::getMethod($subid);
            
            if ($row['payment_identifier'] == "worldline") { // CB
                SubPaymentModuleWorldline::addCardWallet();
            } elseif ($row['payment_identifier'] == "sdd") { // SEPA
                echo 'SEPA Direct Debit!';
            } else {
                echo "oopsi! " .var_dump($row);
                // @TODO gérer
            }

//...

 

Here is the addCardWallet() function:
 

public function addCardWallet($isTest = true) {
        
        $worldline = new Worldline();
        
        // Define the page to redirect after payment
        $protocol = Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://';
        $return_page = $protocol.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__;
        $return_page .= 'subscriptions/main?return=worldline'; // @TODO optimize URL 
        
        
        $atos_mode = true;//stub
        $version_key = $worldline->getVersionKey($atos_mode);
        $merchant_id = '';
        
         // If we are in production mode
        $atos_mode ? $merchant_id = Configuration::get('ATOS_MERCHANT_ID') : 
            $merchant_id = '002001000000001';
        
        
        // Data we need to send 
        // @TODO dynamic merchant wallet Id
        $param = 'merchantId='.$merchant_id.'|normalReturnUrl='.$return_page;
        $param .= '|keyVersion='.$version_key.'|merchantWalletId=14702';
        $param .= '|paymentMeanBrandList=CB,VISA,MASTERCARD';
        $param .= '|requestDateTime='.date("Y-m-d H:i:s");
        
        // Request secure
        $secret_key = worldline::getSecretKey($atos_mode);
        $data = utf8_encode($param);
        $seal = hash('sha256', $data.$secret_key);
        
        $connector_url = 'https://payment-webinit-sogenactif.test.sips-atos.com/walletManagementInit';
        
        /* POST Request without form */
        // data part
        $content = http_build_query(array(
            'Data' => $param,
            'InterfaceVersion' => 'HP_2.9',
            'Seal' => $seal
        ));      
        // protocol part
        $context = stream_context_create(array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-Type: application/x-www-form-urlencoded',
                'content' => $content
            )
        ));
        
        return file_get_contents($connector_url, null, $context);
        
    }

This function create a POST request and send it to the Worldline wallet page.

The problem is that this method doesn't work. Because my front module controller needs to return a template page!
I think I didn't understand how to resolve cleanly my need.
I considere myself good at PHP but need to learn more how to use correctly the Prestashop CMS.

Could you please help me for that?
Thank you.

Tend0

Edited by Tend0 (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...