Coder Social home page Coder Social logo

mpay24-php's People

Contributors

chesio avatar jolicht avatar jrahmy avatar mdaskalov avatar netbull avatar schoradt avatar stefanpolzer avatar tobiaslins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mpay24-php's Issues

Obligate tests and reviews, before merging into master

There are so many small issues the last month, because every one can commit something and it is landing untested in the master branch.

I suggest a testing work flow (e.g. Unit Test), before a commit is considered to be merged into the master branch.
Secondary I suggest that at least two persons should review or test a commit manualy, before the commit is merged into the master branch.

PHP Version 5.3.8 - Parse error: syntax error, unexpected '['

Tested our SDK with PHP Version 5.3.8:
It looks like this PHP version does not support the used array declaration

public function token($paymentType, array $additional = [])
public function createTokenPayment($pType, array $additional = [])
public function acceptPayment($type, $tid, $payment = [], $additional = [])

Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\sdk\src\Mpay24.php on line 189

I think we should only support the supported versions: http://php.net/supported-versions.php

Confusing MPay24Config.php

Implementing this in my point of view results to some issues:

  • it includes config.php which defines the constants which are in any case just defaults and can be set as arguments to the constructor
  • from the above config.php is not needed
  • currently MPay24Config relies on arguments which are specified in surtan order, but which are not documented and it's a bit tricky without reading the constructor

ManualCallback build -> cancel

Mpay Error Message: BIF: incorrect parameter.
If the value of cancel is (bool) false, it will never be appended.
The element is required, when the payment should be done, in case of Payment type Paypal Express.
Before:

        if ($this->cancel) {
            $cancel = $this->document->createElement('cancel', $this->cancel);
            $paymentCallback->appendChild($cancel);
        }

After:

$cancel = $this->document->createElement('cancel', $this->cancel);
            $paymentCallback->appendChild($cancel);

Make the code more robust

Please consider introducing @phpstan as it has great benefits.

I could help as much as necessary.

It is easy to start: phpstan analyze -l 2 src/
phpstan may have problmes with DOMNode class - still there are a lot of benefits!

On payment error no mpaytid

If a payment fails (e.g. using expiry month 01-04 on testsystem), getMpayTid() returns no mpaytid.

echo "ReturnCode: " . $result->getReturnCode();
echo "
";
echo "mPAYTID: " . $result->getMpayTid();

->

ReturnCode: EXTERNAL_ERROR
mPAYTID:

<etp:AcceptPaymentResponse xmlns:etp="https://www.mpay24.com/soap/etp/1.5/ETP.wsdl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="etp:AcceptPaymentResponse">
ERROR
EXTERNAL_ERROR
4100597
100
Karte abgelaufen (card expired)
</etp:AcceptPaymentResponse>


For successful transactions getMpayTid() returns a valid mpaytid.

Compatibility error in PHP 5.4.40

Hello,
When I create the Mpay24 Object i get an error,

Parse error: syntax error, unexpected '.', expecting ',' or ';' in /var/www/clients/client1/web3/web/devp1_1412/vendor26.06.2018/mpay24/mpay24-php/src/Mpay24Sdk.php on line 107 [4] syntax error, unexpected '.', expecting ',' or ';' on line 107 in file /var/www/clients/client1/web3/web/devp1_1412/vendor26.06.2018/mpay24/mpay24-php/src/Mpay24Sdk.php PHP 5.4.40 (Linux)

The fix is change

  /**
     * @var string
     */
    protected $caInfoPath = __DIR__ .  '/bin/';

    public function __construct(Mpay24Config &$config = null)
    {
        if (is_null($config)) {
            $config = new Mpay24Config();
        }

        $this->config = $config;
    }

to this:

    /**
     * @var string
     */
    protected $caInfoPath;

    public function __construct(Mpay24Config &$config = null)
    {
        if (is_null($config)) {
            $config = new Mpay24Config();
        }

        $this->config = $config;
        $this->caInfoPath = __DIR__ .  '/bin/';
    }

Please fix this and check the code for PHP >= 5.3.3 Compatibility.

The "set" methods are not working in Mpay24Order.php

It is not possible to set attributes using the set...() function anymore. An exception At least one Argument must be provided... is always thrown.

Example:
$mdxi->Order->BillingAddr->setMode("ReadOnly");
Throws:
Fatal error: Uncaught InvalidArgumentException: At least one Argument must be provided for node 'setMode'! in /var/www/html/mpay24-php/src/Mpay24Order.php:114 Stack trace: #0 /var/www/html/mpay24-php-tests/min_paypage.php(23): Mpay24\Mpay24Order->__call('setMode', Array) #1 {main} thrown in /var/www/html/mpay24-php/src/Mpay24Order.php on line 114

There should be a return after line 79

Rounding issues

Bug reported by Leonidas D.

mpay24-php / src / Requests / ManualCredit.php

Methode setAmount():

/**
 * @param int $amount
 */
public function setAmount($amount)
{
    $this->amount = (int)$amount;
}

Das TypeCasting das hier via (int) stattfindet kann zu unerwarteten, forcierten Rundungsergebnissen führen, zumindest wo ich es getestet habe.

https://stackoverflow.com/questions/20758881/why-is-php-typecasting-behaving-like-this-int-mis-rounding-numbers

So z.B. ein Fall mit:

$amount=17.90;
// $amount ist hiermit ein float

$mpay24->refund(‘00000000000’, ($amount * 100));
// Übergeben wird nun zwangsläufig ein float, aber halt ohne Nachkommastellen

public function setAmount($amount)
{
$this->amount = (int)$amount;
// $this->amount ist nun 1789
}

Das ist wie es bei den Gutschriften zum Rundungsproblem kam. War halt völlig unerwartet und tauchte beim Test nicht auf, denn interessanterweise gibt es Beträge wo das nicht passiert. 25,90 => kein Problem. 19,20 => kein Problem. 17,90 => Problem!

Natürlich kann man dem entgegenwirken indem man schon vorher einen Integer übergibt. Aber vielleicht wäre in den Funktionen die den Amount annehmen die Erwartung einen Integer zu erhalten besser als es nachher zu typecasten:

/**
 * @param int $amount
 */
public function setAmount(int $amount)
{
    $this->amount = (int)$amount;
}

test.php just feels wrong

dont get me wrong here, but the test.php just looks wrong on many levels.

1.) css should not be inside a public variable of a class
2.) declaring two separate classes and outputting some html in one file feels just wrong.

Also in MPay24Api.php, its properly a good idea to separate the data model and the request/response part.
Some more Code Smells can be found here (german) :
https://de.wikipedia.org/wiki/Smell_(Programmierung)

Any plans for PHPUnit Test's

The most resend changes should show that it s very hard to develop some features if, no tests are available.
Because we are needing the interface on the mPAY24 Server as well that makes it a little bit more difficult.

I'm very customer oriented but I don't know all possible features that are currently supported and,
I don't know also what are the general rule of thumb in your organization how you handle backward compatibility.

Having test cases that must run successful, would make it eraser to see if changes may break things.

Do you see any changes to have some of those Test Cases?

Mpay24Order.php __set() preg_match to strict

if (preg_match('/\b[0-9]+,[0-9]+\b/', $value, $match)) {

This preg_match breaks strings like descriptions with numbers that matches the pattern.

Tested with ShoppingCart->Item( $item_key )->Description = "10,00 € fee"
False Result: 10.00

Requirement: preg_match should not replace attributes / values that are defined as strings in MDXI.xsd (a) or should at least not trim string after matching substring (b).
True Result (a): 10,00 € fee
True Result (b): 10.00 € fee

Cleanup Code relicts in MPAY24 or fully implent it!

I try to understand what happened with the MPAY24 Class.
As it seams this class was once a abstract class and the implementation was done by some other class.

This makes it hard for a newcomer to this project (like me to) to understand what should work, what is just a relict and what is maybe not ready to be used (all a big mess IMHO).

Here are same examples from the MPAY24 Class where there is no implementation:

function createTransaction() { }
function updateTransaction( $tid, $args, $shippingConfirmed ) { }
function getTransaction( $tid ) { }

Than you have a private Method that is not used

private function checkTransaction( $transaction )

Than you have method that no of your customers can use, or they do not complain because they do not need it e.g:

function manualCallback( $tid, $shippingCosts, $amount, $cancel, $paymentType )
function manualClear( $tid, $amount )
function manualCredit( $tid, $amount )
function cancelTransaction( $tid )

One Methods are only working half:

function selectPayment( $mdxi )

no option to provide a redirect back (success, error) or confirmation link, so Customer get error after paying

So the only Methods that are working:

function acceptPayment( $paymentType, $tid, $payment, $additional )
function listPaymentMethods()
function transactionStatus( $mpaytid = null, $tid = null )

IMHO this not very much

MPAY24 Class is also a child of the Transaction Class but for what?
There is no parent method ever used.

I did not Test the MPay24flexLINK Class but It seams to be the same ore worse.

Customised Log Path

If using composer the Package is installed in the following Directory (Base Dir = Project Root):
/vendor/mpay24/mpay24-php/lib

It is very unusual to put the log file into the vendor directory, so it would be nice to have it e.g, /storage/logs

At the moment __DIR__ is hard coded to the write_log Method and I have to do a core hack
or configure the path like

../../../../storage/logs

But this is not working on all OS (e.g. not on Windows Server)

Wrong usage of Constants in Classes

If you have create a more complex application it is easily possible that you have to make more than one SOAP call to the mPAY24 Server within one PHP Batch process.

This leads e.g. to the following Exception:
exception 'ErrorException' with message 'Constant LIVE_ERROR_MSG already defined' in \vendor\mpay24\mpay24-php\lib\MPAY24SDK.php:155

The Reason is very Simple you do not use Class Constants but defining them in a Method.
This lead to a global registered Constants and the next time within the same Batch process, if the Constants is already defined you get the ErrorException

Best Solution would be to use Class Constants
A workaround, but not a Code smell IMHO, would be to add:
if (!defined('LIVE_ERROR_MSG')) define('LIVE_ERROR_MSG', "We are sorry, .... !");

PSR4 Compliance

As mentioned in the PSR-4 Documentation 2.3.3

The terminating class name corresponds to a file name ending in .php. The file name MUST match the case of the terminating class name.

You have 3 Classes in the MPAY24.php file and 7 Classes in the MPAY24SDK.php file.
Im not sure if those are only private classes but if not thay MUST be refactored to a seperat class.

I would recomand:

lib/MPAY24/MPAY24.php
lib/MPAY24/Transaction.php
lib/MPAY24/MPay24flexLINK.php
lib/MPAY24SDK/MPAY24SDK.php
lib/MPAY24SDK/GeneralResponse.php
lib/MPAY24SDK/PaymentResponse.php
lib/MPAY24SDK/PaymentTokenResponse.php
lib/MPAY24SDK/ManagePaymentResponse.php
lib/MPAY24SDK/ListPaymentMethodsResponse.php
lib/MPAY24SDK/TransactionStatusResponse.php
lib/Order/OrderXML.php

http://www.php-fig.org/psr/psr-4/

Missing requirements in composer.json file

Your package have 4 PHP requirements but only one is listed in the composer.json: "php": ">=5.3.3"
For better UX I request to add the others as well:

"ext-curl": "*",
"ext-dom": "*",
"ext-mcrypt": "*"

Unexpected class with PHP 5.4

There is an error while using PHP5.4

Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in [...]/psr4/src/Mpay24.php on line 30

Invalid SOAP-Credentials throws loadXML error

If wrong soap credentials are used, following error message appears:

Warning: DOMDocument::loadXML(): Space required after the Public Identifier in Entity, line: 1 in [...]/phpsdk/src/Responses/AbstractResponse.php on line 60 Warning: DOMDocument::loadXML(): SystemLiteral " or ' expected in Entity, line: 1 in [...]/phpsdk/src/Responses/AbstractResponse.php on line 60 Warning: DOMDocument::loadXML(): SYSTEM or PUBLIC, the URI is missing in Entity, line: 1 in[...]/phpsdk/src/Responses/AbstractResponse.php on line 60

We should present a better error message.
e.g.:

Unauthorized

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

Missing logs Folder in PSR-4 Branch

Testing PSR-4 Branch with Error:
ErrorException in MPAY24.php line 169: fopen(\vendor\mpay24\mpay24-php\lib/./logs/mpay24.log): failed to open stream: No such file or directory
Reason Folder logs is missing.
Just add a Folder logs and put a .gitkeep file in it.

Configuration with a Configuration Object

I have to use the MPAY24 Class quit a lot, so its very inconvenient to put always up to 10 variables if you want to set $enableCurlLog = true;

$mpay24 = new MAP24($merchantID, $soapPassword, $test , $debug, $proxyHost, $proxyPort, $proxyUser, $proxyPass, $verfiyPeer, $enableCurlLog);

Can you just Create another Class e.g. MPay24Config where we can set only the parameter we need and hand over just this one variable?

Very Important is also that the Log Path can be configured with this Object. At the Moment this is done in the configuration file but if a new version comes out this file will be overwritten!!!

A Configuration Object is reusable and I only have to create it once!!!
Example:

$mpay24config = new MPay24Config();
$mpay24config->setUser(98765);
$mpay24config->setPassword(12345);
$mpay24config->setCurlLog(true);
.
.
.
$mpay24 = new MAP24($mpay24config);

If no Object is given the default config.php file could be used es well,
and if you want to have backward compatibility support than,
just make a check if $merchantID is a instance of MPay24Config.

Exception: The schema you have created is not valid! Element 'ShoppingCart': This element is not expected.

https://docs.mpay24.com/docs/working-with-the-mpay24-php-sdk-redirect-integration

when trying to add a ShoppingCard item like displayed above under "Display a shoppingcart on the Payment Page" i get the following error:

Exception: The schema you have created is not valid! Element 'ShoppingCart': This element is not expected. Expected is one of ( Customer, BillingAddr, ShippingAddr, URL )

the XML looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Order>
 <Tid>[tid]</Tid>
 <Price>[price]</Price>
 <Currency>EUR</Currency>
 <ShoppingCart>
  <Item>
   <Number>1</Number>
   <ProductNr>[prod_nr]</ProductNr>
   <Description>[descr]</Description>
   <Quantity>1</Quantity>
   <ItemPrice Tax="2.30">12.30</ItemPrice>
   <Price>12.30</Price> 
  </Item>
  </ShoppingCart>
  <URL>
   <Success>[success_url]</Success>
   <Error>[error_url]</Error>
   <Confirmation>[confirmation_url]</Confirmation>
   <Cancel>[cancel_url]</Cancel>  
  </URL>
 </Order>

"Undefined variable: name" when setting 'BillingAddr' object

Hi,

I have set up the Order object while following the mPAY24 docs. Now as a last step I wanted to fill the BillingAddr object, but when I try to submit the order, before I get forwarded to the payment page, Laravel throws:

ErrorException (E_NOTICE)
Undefined variable: name

error

my pay function:

public function pay(Request $request) {
      $cart = Cart::content();
      $mpay24 = app()->mpay24;
      $mdxi   = app()->mpay24order;

      // dd($cart);

      $mdxi->Order->Tid                   = "1";
      $mdxi->Order->Price                 = Cart::total();

      $mdxi->Order->BillingAddr->setMode("ReadOnly");
      $mdxi->Order->BillingAddr->Name     = 'George';
      $mdxi->Order->BillingAddr->Email    = '[email protected],';
      $mdxi->Order->BillingAddr->Phone    = '3334444555';
      $mdxi->Order->BillingAddr->Street   = 'Foo Street';
      $mdxi->Order->BillingAddr->Zip      = '999';
      $mdxi->Order->BillingAddr->City     = 'Foo City';
      $mdxi->Order->BillingAddr->Country  = 'Foo Country';

      $mdxi->Order->URL->Success      = 'http://mysite.com/success';
      $mdxi->Order->URL->Error        = 'http://mysite.com//error';
      $mdxi->Order->URL->Confirmation = 'http://mysite.com//confirmation';

      $paymentPageURL = $mpay24->paymentPage($mdxi)->getLocation(); // redirect location to the payment page
      return redirect()->to($paymentPageURL);
}

if I comment out the BillingAddr part, the payment gets forwarded to mPAY24, but obviously this is not what I want.

Btw when I open Mpay24Order at line 75, I can't see any refrence to $name.
What could be wrong?

Content breaks on Description

Hi,

i do this in German Website:

$mdxi->Order->ShoppingCart->Item(1)->Description = 'Any cool Product - nur 13,3 kg';
On the final shopping chart i get: 13.3

I fixed this on Mpay24Order.php function __set.

if( $name != 'Description' ) {
            if (preg_match('/\b[0-9]+,[0-9]+\b/', $value, $match)) {
                $value = str_replace(',', '.', $match[0]);
            }
            if (preg_match('/\b[0-9]+.[0-9]+\b/', $value, $match) &&
                $value == $match[0] &&
                $name != 'shippingCosts' &&
                (is_int(strpos($name, 'price')) ||
                    is_int(strpos($name, 'Price')) ||
                    is_int(strpos($name, 'Tax')) ||
                    is_int(strpos($name, 'cost')) ||
                    is_int(strpos($name, 'Cost'))
                )
            ) {
                $value = number_format(floatval($match[0]), 2, '.', '');
            }
        }

Best Regards Thomas

ManualCallback build

There is a wrong space in the ManualCallback build function.
$paymentCallback->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:type', "etp:Callback $this->type");
This will cause the ManualCallback to result in a {"6":"CALLBACK_NOT_ENTERED"} error message

mpay24_php_api, a little impractical to integrate due to MPay24Api::dieWithMsg

Hi

We have to use mpay24-api as part of an abstraction layer for online-payments. Would it be possible to simply throw an exception on certain validation errors within MPay24Api::dieWithMsg instead of calling "die"?

another option which already could help is to make the members of the MPay24Api-Class protected. Doing so i am able to simply inject my own Version of MPay24Api-Class overwriting the methode dieWithMsg.

thanks in advance
cheers
Thomas

Throw exception instead of using die()

Could you please throw exceptions instead of using die(), terminating the whole script?

This practice is quite counter productive when using your library with a framework or in console commands.

There are several places in the code where die('Some reason.') is used.

  • Mpay24.php
  • Mpay24FlexLink.php
  • Mpay24Order.php

Hardcoded directory when debug is enabled

In the MPay24Api class in method send there is an hardcoded log directory set which will be used when debug mode is enabled.

Line 915:
$fh = fopen(__DIR__ . "/../logs/curllog.log", 'a+') or $this->permissionError();

would be nice if we could set the log directory with a parameter in the configuration method.

ErrorException wile running MPAY24 in PHP CLI

Encounter a problem while running in PHP CLI!

I plan to run a cron job that will check for Subscriptions that must be renewed and than calling acceptPayment() on a MPAY24 Object.

The Problem is that this cause the following exception:

exception 'ErrorException' with message 'Undefined index: SERVER_NAME' in \vendor\mpay24\mpay24-php\lib\MPAY24.php:171

Reason is very simple $_SERVER['SERVER_NAME'] is not set in PHP CLI
This will only be set by a Web-server but not in CLI

PSR1 & PSR2

Having the PSR-4 Branch almost ready rises the question about
PSR1 (Basic Coding Standard) & PSR2 (Coding Style Guide)

Some of the rules are already realized some are not. From PSR 1:

  • Class names MUST be declared in StudlyCaps.
  • Method names MUST be declared in camelCase

For PSR 2 the are also a view things that could be improved:

  • Code MUST use 4 spaces for indenting, not tabs.
  • Visibility MUST be declared on all properties and methods;
  • Opening parentheses for control structures MUST NOT have a space after them, and closing parentheses for control structures MUST NOT have a space before.

Most of this can be done with the IDE and on Keystrok,
but the names for Classes in StudlyCaps and Method names in camelCase needs manuel changes.

My suggestion is to change it!

If you have any concerns about the MPAY24 class than we could build a wrapper class with this name and declarer it as deprecated, and remove it in the Next Major Update
This gives you also time to update the documentation accordingly

A good solution IMHO would be: namspace = Mpay24
Class names are:

Mpay24 or Better Mpay24Soap
Mpay24Config
Mpay24FlexLink
Mpay24Sdk
Order or Better Mpay24Order

every other Class Name is alright
All methods will be changed to camelCase

If you agree with it, I could create a pull request.

In the WIKI or somewhere else you could do a article where you declare that you code MUST be written according to dose PSR1 & PSR2 & PRS4 Standards, this makes it easier for every one ho wants to contribute.

AbstractRequest.php Unescaped & in createElement()

The createElement() call in line 112 throws an warning (Warning: DOMDocument::createElement(): unterminated entity reference) and does not set ne child-node correct if you send e.g. for the errorURL an string with & because the value is not escaped by default in this method.
Please add before

$value = str_replace('&', '&amp;', $value);

Similiar is already done in Mpay24Order.php __set() method line 176.

Change method names to standardized names

In order to understand the mpay24 sdk, it is neccessary to adapt all public methods to standardized names.
Here a list for the mapping:

SOAP Call Method Name
selectPayment paymentPage
acceptPayment payment
manualCredit refund
manualReverse cancel
manualClear capture
createPaymentToken token
acceptWithdraw payout
transactionStatus paymentStatus
transactionHistory paymentHistory
createProfile createCustomer
listProfiles listCustomers
deleteProfile deleteCustomer
listNotCleared listAuthorizations
listPaymentMethods paymentMethods

PHP 7.2 Support

Our Project is going to use PHP 7.1 (EOL 1 Dec 2019) and as soon as PHP 7.2 is released (most likely Dec 2017), we will update.
So we need the PHP 7.2 Support if we want to go with mPay24.

As you already mentioned in the Code mcrypt_functions will be removed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.