Jump to content

Recommended Posts

This module is currently broken. I think it was made with version 1 of the Mollie API in mind. If you use it together with the current version of the Mollie API (v2), it does not work at all. Here's a discription of the API changes from v1 to v2 that I think the developer of this module may want to take a look at.

  • Like 1

Share this post


Link to post
Share on other sites

I ran into this issue too. I edited the Mollie module to fit my own needs, a bit too many changes to create a merge request, but it deals with this issue. 

 

<?php namespace ProcessWire;

// Here you can find more information about the Mollie php api https://github.com/mollie/mollie-api-php

require_once __DIR__ . "/vendor/autoload.php";

class PaymentMollie extends PaymentModule
{

    public static function getModuleInfo()
    {
        return [
            'title' => 'PaymentMollie',
            'version' => '0.0.2',
            'summary' => 'Mollie Payment method',
            'singular' => false,
            'autoload' => false,
            'requires' => 'ProcessWire>=3.0.98, PaymentModule',
        ];
    }

    public function init()
    {
        ini_set('display_errors', 1);
        ini_set('display_startup_errors', 1);
        error_reporting(E_ALL);
    }

    public function getTitle()
    {
        return $this->_("Mollie: iDeal, Bancontact");
    }

    public function getFailureReason()
    {
        return "Error";
    }

    public function processPayment()
    {
        $payment_id = wire()->input->post->id;
        $order_id = wire()->input->urlSegment2;

        $mollie = new \Mollie\Api\MollieApiClient();

        $mollie->setApiKey($this->test_api_key);
        if ($this->live_check == "1") {
            $mollie->setApiKey($this->api_key);
        }

        $payment = $mollie->payments->get($payment_id);
        $order_id = $payment->metadata->order_id;

        wire()->log->save("mollie", "Processing payment for... $order_id");

        if ($payment->isPaid() == true) {

            wire()->log->save("mollie", "Order $order_id was paid using mollie!");

            $order = wire()->pages->get($order_id);
            $order->of(false);
            $order->pad_paid = time();
            $order->addNote($this->_("Order paid using Mollie") . ": " . $payment->id);
            $order->removeStatus(Page::statusUnpublished);
            $order->save();

            return true;
        } elseif ($payment->isOpen() == FALSE) {
            return false;
        }
        return false;
    }

    public function getMollieMethods()
    {
        $mollie = new \Mollie\Api\MollieApiClient();

        $mollie->setApiKey($this->test_api_key);
        if ($this->live_check == "1") {
            $mollie->setApiKey($this->api_key);
        }

        $methods = $mollie->methods->all();
        $return = [

        ];

        foreach ($methods as $method) {
            $return[] = [
                "title" => htmlspecialchars($method->description),
                "icon" => htmlspecialchars($method->image->size1x),
                "icon2x" => htmlspecialchars($method->image->size2x),
            ];
        }

        return $return;
    }

    public function render()
    {
        $output = "";

        $mollie = new \Mollie\Api\MollieApiClient();

        $mollie->setApiKey($this->test_api_key);
        if ($this->live_check == "1") {
            $mollie->setApiKey($this->api_key);
        }

        $paymentInfo = [
            "amount"   => [
                    "value" => number_format(($this->getTotalAmount() /100), 2, '.', ''),
                    "currency" => 'EUR',
                ],
            "description" => "Bestelling van: " . $this->customer->givenName . " " . $this->customer->familyName,
            "redirectUrl" => $this->httphost . "checkout/?id=" . $this->id,
            "webhookUrl"  => $this->httphost. "checkout/processmollie/" . $this->id . "/",

            // Specify here wat you want
            "metadata" => [
                "order_id" => $this->id,
                /*
                    "customer_name" => $this->customer->givenName,
                    "customer_familyName" => $this->customer->familyName,
                    "customer_address" => $this->customer->streetAddress,
                    "customer_locality" => $this->customer->locality,
                    "customer_postalCode" => $this->customer->postalCode,
                    "customer_country" => $this->customer->country,
                    "customer_email" => $this->customer->email
                */
            ],
        ];

        // $output .= "<pre>" . print_r($paymentInfo, true) . "</pre>";

        $payment = $mollie->payments->create($paymentInfo);

        wire()->log->save("mollie", "Creating the payment... $order_id");

        // Type here your custom HTML
        // use $payment->getPaymentUrl() as url for your payment link

        foreach ($methods as $method) {
            $output .= '<div style="line-height:40px; vertical-align:top">';
            $output .= '<img src="' . htmlspecialchars($method->image->size1x) . '" srcset="' . htmlspecialchars($method->image->size2x) . ' 2x"> ';
            $output .= htmlspecialchars($method->description) . ' (' . htmlspecialchars($method->id) . ')';
            $output .= '</div>';
        }
        $output .= "</div>";

        $output  .= "<div><form action='{$payment->getCheckoutUrl()}'>
            <button type='submit'>". __('Pay') ."</button></form></div>";

        return $output;
    }

    public static function getModuleConfigInputfields(array $data)
    {
        $inputfields = new InputfieldWrapper();

        // Test API
        $live_api_field = wire('modules')->get('InputfieldText');
        $live_api_field->name = 'test_api_key';
        $live_api_field->label = __("Test API Key");
        $live_api_field->notes = __("");
        if (isset($data['test_api_key'])) {
            $live_api_field->value = $data['test_api_key'];
        }

        $inputfields->add($live_api_field);

        // Live API
        $test_api_field = wire('modules')->get('InputfieldText');
        $test_api_field->name = 'api_key';
        $test_api_field->label = __("Live API Key");
        $test_api_field->notes = __("");
        if (isset($data['api_key'])) {
            $test_api_field->value = $data['api_key'];
        }

        $inputfields->add($test_api_field);

        // Select live or test API
        $check_api_field = wire('modules')->get('InputfieldCheckbox');
        $check_api_field->name = 'live_check';
        $check_api_field->checked = $data['live_check'];
        $check_api_field->label = __("Use Live API Key");
        $check_api_field->notes = __("If not selected, the test-api will be used. Keep in mind that you also have to activate the Live api on your Mollie dashboard");
        if (isset($data['live_check'])) {
            $check_api_field->value = $data['live_check'];
        }

        $inputfields->add($check_api_field);

        // HTTP Host url
        $httphost_field = wire('modules')->get('InputfieldURL');
        $httphost_field->name = 'httphost';
        $httphost_field->label = __("HTTP Host");
        $httphost_field->notes = __("");
        if (isset($data['httphost'])) {
            $httphost_field->value = $data['httphost'];
        }

        $inputfields->add($httphost_field);

        return $inputfields;
    }
}

 

  • Like 1

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By kongondo
      Announcing the current status, planned release, roadmap and preview of Padloper 2.
      Status
      Feature freeze. Full multilingual support. Only PHP 7.2+ supported. Support for ProcessWire 3.0 only. Backend support for modern browsers only (that support JavaScript ES6 modules). Current Work
      Finish work on admin/backend. Work on installer and uninstaller (including configurable availability of some features). Work on UI/UX improvements. Start work on documentation with special focus on technical documentation. Continue work on Padloper API and data/model component. Roadmap
      Please note that these ARE NOT hard and fast targets. The roadmap may have to be adjusted to accommodate technical and non-technical constraints.
      Q1 2021
      Inbuilt support for (latest) PayPal (full rewrite, no external modules required). Additional work on Padloper API. Invite a limited number of early alpha testers (fully-priced product). Soft and closed release of Padloper 2.
      Q2 2021
      Start work on relaunch of Padloper website. Inbuilt support for Stripe (no external modules required). Future Plans
      Support for more Payment Gateways. Support for order, customers, etc imports and exports. Support for AdminThemeReno and AdminThemeDefault. Separate fully-featured frontend shop module. Consider support for multiple currencies. FAQ
      1. Have you abandoned this project? 
      No.
      2. When will Padloper 2 be released?
      First early alpha release is scheduled for Q1 2021. This target may change depending on circumstances! Access will be by invite only for this first release.
      3. What is the pricing model of Padloper 2? 
      Three licences: Single Site, Developer and Agency licences (12 months’ updates and VIP support).
      4. How much will Padloper 2 Cost?
      No price has been set yet. It will cost more than Padloper 1.
      5. Can we upgrade from Padloper 1?
      No.
      6. Will existing users of Padloper 1 get a discount for Padloper 2?
      No, this will not be possible. Apologies for the earlier announcement. It was unrealistic and unworkable.
      7. Can we pay for Padloper 2 in advance?
      No.
      8. Does Padloper 2 render markup/templates in the frontend?
      No. Access to all data you need to build your shop’s frontend is via the Padloper API.
      9. Can we keep sending you ‘Are we there yet’ messages?
      No, please.
       
      Preview
      Here is a video preview of the current state of the backend/admin of Padloper 2. Please note the following:
      This is early alpha. There are bugs! It even includes WIP/notes!! FOUC, misaligned things, etc. The video shows the near-raw implementation of Vuetify UI. The UI/UX improvements work is yet to start. What you see here is the development version.  Some of the incomplete features may not be available in the early releases. Most of the features you see will be optional to install.  

       
    • By picarica
      Hello so i am unable to get to cart/checkout menu , not sure how you even set it up, in the guide it just happend with no setup so what i got it is that i press submit after selecting product, and then it said that item is out of stock even tho i have 50 quantiny in the page, so i enabled negative stock so i could test this out and its weird
      after submit with negative stock i enabled i get this in the url
      localhost/vsetky-produkty/black2/?productId=1065&variationId=0&qty=1&totalQty=8&numberOfTitles=4&totalAmount=0
      but nothing in the page changes ? where is the next step, next step in the official website is payment modules
    • By picarica
      so hello i managed to make every step in padloper guide here https://www.padloper.pw/documentation/product-variations/
      but i got stuck that when i create my final product list those products dont have any check boxes, even tho when making color or size field i checked that there will be one choice only and yet when seen on the page its empty, any idea where i should be looking for fix ? i already tried to re-do the whole process but still same i am rpobably doing somethign wrong

    • By Jeannette
      Hello Fellows,

      I have a wonderful webshop, using PL and Padopt, a module developed by Julien Vaubourg and highlighted in ProcessWire Newsletter. Here is our shop: cheval-ami.fr
      I am looking for a new developer, helping me to keep the shop smooth and up to date.
      We would like to improve automated invoicing and worldwide shipping, getting DHL integrated and give people the possibility to create their personal accounts and be the nicest shop in the equine industry. We are still a young company, working all in german, english and french. We are very interested in a long time, kind and friendly relationship without any stress, but reliable reactivity in case of urgency. 
      We are based in Hamburg and near Paris and would prefere to work with somebody who is available to catch up around a table, at least sometimes.
      Contact: mail@cheval-ami.fr or +33 626 22 1000 or +49 170 20 28 215
      Thank you, Have a beautiful day,
      Jeannette
    • By Chris B
      Hi,
      I have to develop an e-commerce for a client who sells trips. He wants the customer to be able to enter the contact details for each participant in the order process.
      Ex: if I order a stay for two participants, then in the order process, I should have two information area for each person (firstname, lastname, address, birth, etc.). Then I will have to store the data in the order.
      Can we customize padloper like this?
      thank u
×
×
  • Create New...