sofort / sofortlib-php

SOFORT API wrapper for PHP
Other
65 stars 16 forks source link

How to Get the Response Back after success payment #23

Closed shoaibgits closed 7 years ago

shoaibgits commented 7 years ago

I am Trying to get the Response back after the success payment with the sofort integration but not getting anything in response;

Error: Error: 7000:Invalid XML.

here is the success function:

  public function successAction()
{   

    $configkey = 'my_key';

    $SofortLib_Notification = new Notification();

    $TestNotification = $SofortLib_Notification->getNotification(file_get_contents('php://input'));

    echo $SofortLib_Notification->getTransactionId();
    echo '<br />';
    echo $SofortLib_Notification->getTime();
    echo '<br />';

    $SofortLibTransactionData = new TransactionData($configkey);

    $SofortLibTransactionData->addTransaction($TestNotification);

    $SofortLibTransactionData->setApiVersion('2.0');

    $SofortLibTransactionData->setTime('2012-11-14T18:00+02:00', '2012-12-13T00:00+02:00');
    $SofortLibTransactionData->setNumber(5, 1);

    $SofortLibTransactionData->sendRequest();

     echo '<pre>'; print_r($SofortLibTransactionData);
    //exit();
    $output = array();
    $methods = array(
        'getAmount' => '',
        'getAmountRefunded' => '',
        'getCount' => '',
        'getPaymentMethod' => '',
        'getConsumerProtection' => '',
        'getStatus' => '',
        'getStatusReason' => '',
        'getStatusModifiedTime' => '',
        'getLanguageCode' => '',
        'getCurrency' => '',
        'getTransaction' => '',
        'getSenderAccountNumber' => '',
        'getSenderBankCode' => '',
        'getSenderCountryCode' => '',
        'getSenderBankName' => '',
        'getSenderBic' => '',
        'getSenderIban' => '',
        );

    foreach($methods as $method => $params) {
        if(count($params) == 2) {
            $output[] = $method . ': ' . $SofortLibTransactionData->$method($params[0], $params[1]);
        } else if($params !== '') {
            $output[] = $method . ': ' . $SofortLibTransactionData->$method($params);
        } else {
            $output[] = $method . ': ' . $SofortLibTransactionData->$method();
        }
    }

    if($SofortLibTransactionData->isError()) {
        echo $SofortLibTransactionData->getError();
    } else {
        echo implode('<br />', $output);
    }

    // $sofortTans = new TransactionData;
    // echo '<pre>';print_r($sofortTans);
    // $viewModel = new ViewModel(array('status' => $sofortTans));
    // $viewModel->setTemplate('layout/pay_done');

    // return $viewModel;
}

And Here the Action method in my contrller to send the request can you please guide me how i can get the Response back ?

                $configkey = 'my_config_key';

                $Sofortueberweisung = new SofortUeberWeisung($configkey);

                $Sofortueberweisung->setAmount($request->getPost('grandtotal_price'));
                $Sofortueberweisung->setCurrencyCode('EUR');
                $Sofortueberweisung->setReason('Single Coupon Order', 'Voucher Codes');
                $Sofortueberweisung->setSuccessUrl('http://localhost:8088/payment/success', false);
                $Sofortueberweisung->setCustomerprotection(true);

                $Sofortueberweisung->sendRequest();

                if($Sofortueberweisung->isError()) {
                // SOFORT-API didn't accept the data

                    echo $Sofortueberweisung->getError();
                } else {

                // get unique transaction-ID useful for check payment status
                    $transactionId = $Sofortueberweisung->getTransactionId();
                // buyer must be redirected to $paymentUrl else payment cannot be successfully completed!
                    $paymentUrl = $Sofortueberweisung->getPaymentUrl();
                    $this->redirect()->toUrl($paymentUrl);
                //header('Location: '.$paymentUrl);
                }
VasuLief commented 7 years ago

Hello shoaibgits, sorry for the late answer.

Our example for the TransactionData-API is a little misleading here. You can either get a single transaction via

$SofortLibTransactionData->addTransaction($transactionId);

or multiple transactions with search parameters via

$SofortLibTransactionData->setTime('2017-06-01T18:00+02:00', '2017-06-18T00:00+02:00');
$SofortLibTransactionData->setNumber(5, 1); // limit to 5 transactions

but never both in the same api call.

Hope this helps VasuLief

VasuLief commented 7 years ago

I guess this issue is solved.

shoaibgits commented 7 years ago

I have tried but not worked for me will share the new faced issues.

shoaibgits commented 7 years ago

Actually what i was looking for is the response back after the successful payment transaction. If a user placed order and pay the payment using the Sofort and on return back to the website i need the response of current transaction.