2

Trying to implement custom payment using SOAP. Payment system has working examples for php5 https://shop.nets.eu/web/partners/sample-code.

Soap works fine if I run this samples as plain PHP, but inside magento Soap fails.

When I send payment confirmation on checkout I Recieve error from magento REST:

http://mat24.dev/rest/default/V1/guest-carts/62398ebea871c954c98044c1fbe1da1f/payment-information

Status Code:400 Bad Request

{"message":"Unable to place order. Please try again later."}

Code fails at this string

$OutputParametersOfRegister = $client->__call()

Inside capture method I debugged all information and everything is ok, but I cannot see whats going on when I use Soap::__call()

My capture method is approximately looks like this:

public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
    {

        try {
            $merchantId = $this->getConfigData('merchant');
            $token = $this->getConfigData('token');
            $wsdl = $this->getConfigData('wsdl'); 
            $terminal = $this->getConfigData('terminal'); 


            $InputParametersOfRegister = array
            (
                "token"      => $token,
                "merchantId" => $merchantId,
                "request"    => $RegisterRequest
            );

            $client = new \SoapClient($wsdl,
                    ['trace' => true, 'exceptions' => true]);


            $this->log->info("P A Y M E N T  before __call"); //this logging is visible
            // Following string causes some error
            $OutputParametersOfRegister = $client->__call('Register', ["parameters" => $InputParametersOfRegister]);
            $RegisterResult = $OutputParametersOfRegister->RegisterResult;

            $this->log->info("P A Y M E N T  after __call"); // this logging is invisible
            }
            catch (\Exception $e) {
                $this->log->error('PAYMENT ERROR : ' . $e->getCode() . ' ' . $e->getMessage());
                throw new \Magento\Framework\Validator\Exception(__('Payment capturing error.'));
            }
    }

Please, any ideas how to debug it or what is the issue?

2 Answers 2

2

You need to wrap your soap call into try and catch construction to find a reason of your error. This can be done in the follows way:

$client = new \SoapClient($wsdl, ['trace' => true]);
try {
    // use client to call some soap method
} catch (\SoapFault $e) {
    // handle exception message
}

This construction allows to do next two things:

  1. You can get exception message -> $e->getMessage() and exception details $e->detail.
  2. The trace option allows seeing details of your $client request. For example, if you use xdebug and set break point in the catch block, you can get request and response details: $client->__last_request and $client->__last_response, which allow you to find reason of your problem
1
  • Thanx. That's a correct answer as I solve this problem before. Actually I placed $client->__call('Register', ["parameters" => $InputParametersOfRegister]); into try-catch and it works. I recieve an error in log, but when I used try-catch for whole code it breaks after $client->__call and don't display error.
    – white-imp
    Commented Jul 7, 2016 at 9:57
0

Your request parameters may be getting stripped if they don't comply with what is described in the WSDL.

For more info on this look here: http://php.net/manual/en/soapclient.call.php

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.