Giter VIP home page Giter VIP logo

sofortlib-php's Introduction

SofortLib-PHP @ SOFORT GmbH

Build Status

This documentation explains the SofortLib PHP, its parts, how to set it up and how to test it.

DESCRIPTION

Integrate the SofortLib PHP into your project to communicate via PHP with the SOFORT API.

Find out more about the SOFORT API/SDK here: https://www.sofort.com/integrationCenter-eng-DE/integration/API-SDK/

SofortLib PHP Supports the following SOFORT Products:

  1. SOFORT Überweisung (SOFORT Banking/Payment)
  2. SOFORT Paycode
  3. SOFORT Billcode
  4. Refund
  5. iDEAL

Install

Install the sofort/sofortlib-php package using composer:

{
    "require": {
        "sofort/sofortlib-php": "3.*"
    }
}

SofortLib Package

The SofortLib PHP package contains the following:

  • the /src directory with the class-files
  • an /examples folder, with examples of usage
  • the folder /test with the unittests (for PHP Unit).

Functionality

  • initiate a SOFORT Überweisung
  • create/initiate a SOFORT Überweisung Paycode
  • create/initiate a SOFORT Überweisung Billcode
  • getting the details for one or more transactions
  • getting the details for a period and/or status
  • convert received XML to a PHP Object
  • marking refunds
  • getting the current iDEAL Bank list
  • generate a forward URL for the iDEAL payment data
  • creating checksum/hash for iDEAL Payment data
  • creating checksum/hash for iDEAL Notifications

Usage

Find examples of usage for the different modules in the /examples directory.

Testing

Run the tests

./vendor/bin/phpunit

sofortlib-php's People

Contributors

vasulief avatar lxlang avatar chmoelders avatar katzefudder avatar ctwsb avatar fruumanstuck avatar 0x20h avatar vojtasvoboda avatar stockii avatar valeriitropin avatar

Stargazers

Ginsky avatar  avatar Rich avatar Akın Ayturan avatar kovalev avatar  avatar  avatar Jefferson Magboo avatar Christian Weber avatar Samet Özden avatar Lion Rexhepi avatar Christian Stoller avatar Robert Freigang avatar Moritz Fromm avatar Povilas Brilius avatar Deniz Burucu avatar  avatar David Behler avatar Alexander Waclawczyk avatar hassan avatar Tim Helfensdörfer avatar Akos Szente avatar Christoph Hautzinger avatar Antonio Ramirez avatar  avatar Vadym Panchenko avatar  avatar Chun-Sheng, Li avatar Manuel avatar Hansu.Hessu avatar David Zacharias avatar  avatar Brian Faust avatar Ismayil Khayredinov avatar Alexander Musichen avatar Thorsten avatar David Albrecht avatar Vadim avatar Bernd avatar  avatar Alexander Salas Bastidas avatar Aronne Brivio avatar Patric Gutersohn avatar  avatar Mathieu Boillat avatar Michael Malik avatar Raphael Leroux avatar Steffen Kowalski avatar Vasily Bezruchkin avatar Oliver Vogel avatar  avatar  avatar  avatar canbeing avatar Christian avatar Vince749 avatar  avatar  avatar  avatar Andreas avatar Heiko S. avatar  avatar Peter Gabriel avatar  avatar  avatar

Watchers

 avatar  avatar Jórgos Skettos avatar James Cloos avatar Michael Roskosch avatar Sascha Henry avatar Rico Simlinger avatar Thomas avatar  avatar  avatar Ivan avatar  avatar Alexander Nostadt avatar  avatar Clemens Weiß avatar  avatar  avatar Heiko S. avatar  avatar Christian Weber avatar FxAlex avatar  avatar  avatar Team Myrddin avatar

sofortlib-php's Issues

autoload.php file is missing

I cant find the autoload.php. as a result the api is not working. can you please help?
Here are the errors:
`Warning: require(/www/webseiten/testing/sofort/examples/../vendor/autoload.php): failed to open stream: No such file or directory in /www/webseiten/testing/sofort/examples/Paycode.php on line 4

Fatal error: require(): Failed opening required '/www/webseiten/testing/sofort/examples/../vendor/autoload.php' (include_path='.:/usr/share/php') in /www/webseiten/testing/sofort/examples/Paycode.php on line 4`

Refund API: 5003 error

I am seeing strange behavior from the Refund API. No matter what amount of the refund I set, I get the 5003 Amount must not exceed transaction amount. error.
I have verified that transaction exists and it's amount is 100 Eur. No matter if I set the amount to 1, 99, or 100 EUR, I get the same error. Am I missing something?

How to Get the Response Back after success payment

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);
                }

Feature-Request: Please add IDENT API

The latest german Youth Protection Act require shops to verify the age of visitors, if they are selling Alcohol, Tobacco, etc and the most mentioned "postident" way is no working solution for the web.

Because of the requirement, that already the browsing of an e-smoking webshop has to be denied to minors, the IDENT API seems to be a real alternative, and the only known implementation seems to be in xt:commerce

In my opinion, an open source implementation of this API would help the "Product" itself too, so i ask you to consider the inclusion of this API into the sofortlib-php.

TransactionData() only returns false

I want to get the status of a specific transaction on the basis of a transaction ID.

This is my code:

<?php
$config_key = '12345:123456:edc788a4316ce7e2ac0ede037aa623d7'; // I'm using my correct one; This is from your examples
$transaction_id = '00907-01222-51ADD8C9-86C8'; // I'm using a correct one; This is from your examples

$transaction_data = new TransactionData($config_key);
$transaction_data->addTransaction($transaction_id);
$transaction_data->setApiVersion('2.0');

$transaction_data->sendRequest();

if($transaction_data->isError()) {
	echo $transaction_data->getError();
} else {
	$output = array();

	$output[] = 'getStatus' . ': ' . $transaction_data->getStatus();
	$output[] = 'getStatusReason' . ': ' . $transaction_data->getStatusReason();

	echo implode('<br />', $output);
}

I always land in the else condition, so $transaction_data->isError() is always false. But unfortunately, $transaction_data->getStatus() is also only false - it doesn't contain any status.

What's my issue? Do I even use the correct code to archive my goal?

PHP 8.1 uses HTML parsing functions in other way

Missing Proxy-Support

We want to integrate your SDK into our system. On our servers for security reasons all outgoing requests must go through a proxy server that has a URL whitelist. Could you add the possibility to set either the HTTP client or at least set the proxy headers for the curl client? This would be awesome. Thanks, Kay

Unable to get Transaction ID in Notification Url or success url Integrated in zend2 ?

    public function sofyAction()
    {
        $args = [ 'config_key' => $this->getConfigKey() ];
        $sofy = new Api($args);
        
        $helper = $this->getServiceLocator()->get('ViewHelperManager')->get('ServerUrl');
        $successUrl = $helper($this->url()->fromRoute('sofort_response'));
        
        $params = [
            'amount' => 1500,
            'currency_code' => 'EUR',
            'reason' => 'Vouhcer Order',
            'success_url' => $successUrl,
            'customer_protection' => false,
            'notification_url' => 'MY_PRIVATE_RESPONSE_URL',
        ];
        
        $trans = $sofy->createTransaction($params);
        return $this->redirect()->toUrl($trans['payment_url']);
    }

How to get response and transaction ID as given it API document in Notifiaction url and on success url too , please unable to find any help or guide for it ?

Sofort getPaymentUrl Timeout

I wonder how long the getPaymentUrl is valid. Is the client don't pay for some hours for example, can we still resend the same getPaymentUrl or should we generate a new one for the same order ?

All the best.

Multiple Reasons do not work

Probably the PHP Library do not format it the way the API likes it to have:

Example Request:

$s = Sofortueberweisung('...');
///...
$s->setReason('Testueberweisung', 'Verwendungszweck', 'p1');
$s->setReason('Testueberweisung2', 'Verwendungszweck2', 'p2');
echo json_encode($s->getParameters());

outputs:

{
   "su":[

   ],
   "amount":56,
   "currency_code":"EUR",
   "sender":{
      "country_code":"DE"
   },
   "p1":{
      "reasons":{
         "reason":[
            "Testueberweisung",
            "Verwendungszweck"
         ]
      }
   },
   "p2":{
      "reasons":{
         "reason":[
            "Testueberweisung2",
            "Verwendungszweck2"
         ]
      }
   },
   "success_url":"...",
   "success_link_redirect":true,
   "abort_url":"...",
   "notification_urls":{
      "notification_url":[
         {
            "@data":"..."
         }
      ]
   }
}

The API returns as error messages:

array(2) {
  [0]=>
  array(3) {
    ["code"]=>
    string(4) "8054"
    ["message"]=>
    string(59) "All products deactivated due to errors, initiation aborted."
    ["field"]=>
    string(0) ""
  }
  [1]=>
  array(3) {
    ["code"]=>
    string(21) "8010.reasons.reason.1"
    ["message"]=>
    string(18) "Must not be empty."
    ["field"]=>
    string(16) "reasons.reason.1"
  }
}

test mode for payCode - work?

in My projects -> Project -> Sofort -> Options -> Test mode: -> Set checked

run this code:

    $configkey = env('SOFORT_API_KEY');

    $SofortLibPaycode = new Paycode($configkey);

    $SofortLibPaycode->setAmount(1.00)
       ->setLanguageCode('de')
        ->setCurrencyCode('EUR')
        ->setReason('sofort.com - Test', '8fb8400661')
        ->setSuccessUrl('http://lvh.me:8000/success')
        ->setSuccessLinkRedirect(1)
        ->setAbortUrl('http://lvh.me:8000/abort')
        ->setNotificationUrl('http://lvh.me:8000/notify')
        ->setUserVariable('Test123');

    $SofortLibPaycode->createPaycode();

and I get: Error: 6100:Paycode request could not be processed.

SOFORT Überweisung: Which transaction were aborted?

I'm a bit confused with the process of SOFORT Überweisung.

When I hit the "Cancel" button on the payment site, it redirects me to my set AbortURL, but I don't get any GET or POST information about the canceled payment. The Transaction ID would be already very nice - or any other custom key, which identifies which transaction were aborted.

Is there a way to get such information?

Local development systems aren't supported

I develop on my local machine. The same code, which is working on our STAGE and LIVE server, doesn't work in my local system, because the library can't resolve my local system URL like https://my.shop.local/payment/notification.

Due of that, I'm getting the following error:

"code" => "8016"
"message" => "Must be a valid URL."
"field" => "notification_urls.notification_url.1"

Is there a way to support local development?

// Edit: I'm talking about SOFORT Überweisung.

getTransactionId() not work correct

hi, i don't understand what is going. Making file, based on examples, do request, after do getNotification(file_get_contents('php://input')). But if i trying echo getTransactionId() it is empty, and output array

$output = array();
$methods = array(
    'getAmount' => '',
    'getAmountRefunded' => '',
    'getCount' => '',
    'getPaymentMethod' => '',
    'getConsumerProtection' => '',
    'getStatus' => '',
    'getStatusReason' => '',
    'getStatusModifiedTime' => '',
    'getLanguageCode' => '',
    'getCurrency' => '',
    'getTransaction' => '',
    'getReason' => array(0,0),
    'getUserVariable' => 0,
    'getTime' => '',
    'getProjectId' => '',
    'getRecipientHolder' => '',
    'getRecipientAccountNumber' => '',
    'getRecipientBankCode' => '',
    'getRecipientCountryCode' => '',
    'getRecipientBankName' => '',
    'getRecipientBic' => '',
    'getRecipientIban' => '',
    'getSenderHolder' => '',
    '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();
    }
}

is empty. Can you explain this?
Hope, You understand what i mean :)

Why is this notification URL not valid?

As notification URL, I have set: http://myhost.local/?id=535&type=4840&mail_id=837&success=notify
Why does the API return : 8016.notification_urls.notification_url.1:Must be a valid URL.?

  • Is it because it is a different host than my sofort account?
  • Or because it's not HTTPS?
  • Or because it's not reachable from the internet? (dns resolve)
  • Or simply because it contains '.local'?

Of course I don't assume notification to work. But as I am developing on my local machine, I try to code as much as possible there before pushing it on the staging server. Please add more information to the API documentation which URL validation checks are in place.

Status Reason: sofort_bank_account_needed

I'm a bit confused regarding the status_reason sofort_bank_account_needed.

Please keep in mind that if a Online Bank Transfer transaction has been successfully finished and Sofort GmbH has received the confirmation from the buyer's bank, Sofort GmbH reports the status "untraceable - sofort_bank_account_needed" (without Deutsche Handelsbank account) or "pending - not_credited_yet" (with Deutsche Handelsbank account). Both status messages have the equivalent meaning and represent the real-time transaction confirmation that should be processed by the merchant's online shop system.

Source: Status Messages / Codes, Table 6

I understand this quote as it means, the transaction was successful - the user paid the money and I got the money. So it should be the status credited.

But... When I read more, it sounds like as it isn't credited as sofort_bank_account_needed is only an alias for not_credited_yet (not paid yet; waiting for money).

Based on this understanding, I've created a simple switch-case:

<?php
// [...] $transaction = [...]

switch($transaction->getStatusReason()) {
	case "not_credited":
		// The money has not been received.
		echo 'Success: Accepted not_credited event.';
		break;
	case ("not_credited_yet" || "sofort_bank_account_needed"):
		// The money has not yet been received.
		echo 'Success: Accepted not_credited_yet event.';
		break;
	case "credited":
		// The money has been received.
		echo 'Success: Accepted credited event.';
		break;
	case "compensation":
		// The money has been refunded (partial refund).
		echo 'Success: Accepted compensation event.';
		break;
	case "refunded":
		// The money has been refunded (complete refund of total amount).
		echo 'Success: Accepted refunded event.';
		break;
}

The only case, where the status_reason means, that the customer has paid and I got the money, is credited.

Using my above code snippet, the notification always ends in the case ("not_credited_yet" || "sofort_bank_account_needed"):, when I test a bank transfer using the Demo bank and any of the test bank accounts.

It seems like as the status does never change to "paid" (credited), so I'm not able to tell the user, that the transaction was successful.

What's right here now? What does sofort_bank_account_needed mean and which case should it match?

Thank you in advance for your support!

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.