Last updated: 04-Dec-2020
Rate this article:
Overview
SOFORT is a payment method used primarily in Germany, Austria, Belgium, Switzerland, and The Netherlands. SOFORT supports a direct credit transfer system designed to allow the immediate delivery of goods and services through instant notification and confirmation support.
Currencies
SOFORT supports transactions in EUR and CHF.
Workflow
- Shoppers select SOFORT as a payment option in the checkout interface you provide to them.
- Create the order object. Use “SOFORT” as the type of the PaymentDetails object.
- Use the placeOrder method to send the data to 2Checkout.
- Use the PaymentMethod object to create a redirect URL for the shoppers. Using the provided URL, make a request using the provided method (usually a GET request) and add the parameters (located in the Params object) as key-value pairs to the URL of the request.
- 2Checkout returns an Order object as the output of the placeOrder method.
- Once you place the order, 2Checkout logs it into the system. At this point in time, the status of the order is PENDING.
Parameters
Parameters | Type/Description |
---|---|
sessionID |
Required (string) |
|
Session identifier, the output of the Login method. Include sessionID into all your requests. 2Checkout throws an exception if the values are incorrect. The sessionID expires in 10 minutes. |
Required (Object) |
|
|
Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details. See code sample for more details. |
Request sample
<?php
/**
* Sofort place order SOAP v6.0
*/
$apiVersion = '6.0';
$url = "http://api.avangate.local:8081/soap/".$apiVersion."/";
$sb = "10";
$client = new \SoapClient($url."?wsdl", array('location' => $url, 'cache_wsdl' => WSDL_CACHE_NONE));
// IdAccount 21478
$merchantCode = "120000589445";
$key = "i9u2+w8%s4^5#8%t)A8?";
$productCode = "BDG8899343FE";
$date = gmdate('Y-m-d H:i:s');
$string = strlen($merchantCode) . $merchantCode . strlen($date) . $date;
$hash = hash_hmac('md5', $string, $key);
$client->__setCookie('XDEBUG_SESSION', 'PHPSTORM');
try {
$sessionID = $client->login($merchantCode, $date, $hash);
} catch (SoapFault $e) {
echo 'Login error: ' . $e->getMessage();
die();
}
var_dump("sessionID: ", $sessionID);
$currency = 'EUR';
//$currency = 'USD';
$country = 'DE'; $state = ''; $city = 'Munchen';
//$country = 'US'; $state = 'GA'; $city = 'Atlanta';
$phone = '0049-0130-5529901';
$CartObj = new stdClass();
$CartObj->Currency = $currency;
$CartObj->Language = "EN";
$CartObj->Country = $country;
$CartObj->CountryCode = $country;
$CartObj->CustomerIP = '91.220.121.21';
$CartObj->Source = "sourceAPI.net";
//$CartObj->ExternalReference = "API2.5_PLACE_ORDER_EXT_" . date("Y-m-d h:m:i");
//$CartObj->AffiliateId = 10244;
$CartObj->LocalTime = date('Y-m-d H:i:s');
$CartObj->CustomerReference = '421820' . strval(rand (100, 999));
$CartObj->Items = array();
$CartObj->Items[0] = new stdClass();
$CartObj->Items[0]->Code = $productCode;//"3333399999_COPY1";//"155887799"; - vld_licence_1month //"12345"; -vld_regular
$CartObj->Items[0]->Quantity = 1;
//$CartObj->Items[0]->Price = 3;
$CartObj->Items[0]->PriceOptions = [];
$priceOption = new stdClass();
$priceOption->Name = 'Users';
$priceOption->Code = 'USERS_1';
$priceOption->Options = [];
$priceOptionOption = new stdClass();
$priceOptionOption->Name = '10 users';
$priceOptionOption->Value = '10_users';
$priceOptionOption->Surcharge = 0;
$priceOption->Options[] = $priceOptionOption;
$CartObj->Items[0]->PriceOptions[] = $priceOption;
$priceOption2 = new stdClass();
$priceOption2->Name = 'Maintenance period';
$priceOption2->Code = 'MAINTE_PERIOD';
$priceOption2->Options = [];
$priceOptionOption2 = new stdClass();
$priceOptionOption2->Name = '12 months';
$priceOptionOption2->Value = 'jira_maintenance_12_mths';
$priceOptionOption2->Surcharge = 0;
$priceOption2->Options[] = $priceOptionOption2;
$CartObj->Items[0]->PriceOptions[] = $priceOption2;
/**/
$additionalField1 = new stdClass();
$additionalField1->Code = "additional_field_order_1";
$additionalField1->Text = "REST";
$additionalField1->Value = "1";
$additionalField2 = new stdClass();
$additionalField2->Code = "additional_field_order_2";
$additionalField2->Text = "REST";
$additionalField2->Value = "a";
$additionalField3 = new stdClass();
$additionalField3->Code = "additional_field_order_3";
$additionalField3->Text = "REST";
$additionalField3->Value = "a";
$CartObj->AdditionalFields = array();
$CartObj->AdditionalFields[0] = $additionalField1;
$CartObj->AdditionalFields[1] = $additionalField2;
$CartObj->AdditionalFields[2] = $additionalField3;
$additionalField1 = new stdClass();
$additionalField1->Code = "additional_field_product_1";
$additionalField1->Text = "PRODUCT1 TEXT";
$additionalField1->Value = true;
$CartObj->Items[0]->AdditionalFields = array();
$CartObj->Items[0]->AdditionalFields[0] = $additionalField1;
//$CartObj->Promotions = ["48606DBB"];
$CartObj->MachineId = 'machineIdTestAlexB';
$CartObj->Discount = null;
$CartObj->ExternalReference = null;
$CartObj->BillingDetails = new stdClass();
$CartObj->BillingDetails->IsCompany = false;
//$CartObj->BillingDetails->Company = '';
$CartObj->BillingDetails->Address1 = '37 Mannheim Strasse, A8';
$CartObj->BillingDetails->Address2 = 'floor 3';
$CartObj->BillingDetails->City = $city;
$CartObj->BillingDetails->State = $state;
$CartObj->BillingDetails->CountryCode = $country;
$CartObj->BillingDetails->Phone = $phone;
$CartObj->BillingDetails->Email = 'reinhardt@trashmail.net';
$CartObj->BillingDetails->FirstName = 'Willy';
$CartObj->BillingDetails->LastName = 'Reinhardt';
$CartObj->BillingDetails->Zip = 99234;
/**/
$CartObj->DeliveryDetails = new stdClass();
$CartObj->DeliveryDetails->Address1 = '37 Mannheim Strasse, A8';
$CartObj->DeliveryDetails->Address2 = 'floor 3';
$CartObj->DeliveryDetails->City = $city;
$CartObj->DeliveryDetails->State = $state;
$CartObj->DeliveryDetails->CountryCode = $country;
$CartObj->DeliveryDetails->Phone = $phone;
$CartObj->DeliveryDetails->Email = 'reinhardt@trashmail.net';
$CartObj->DeliveryDetails->FirstName = 'Willy';
$CartObj->DeliveryDetails->LastName = 'Reinhardt';
$CartObj->DeliveryDetails->Zip = 99234;
/**/
$CartObj->PaymentDetails = new stdClass();
$CartObj->PaymentDetails->Type = 'DIRECT_EBANKING';
$CartObj->PaymentDetails->Currency = $currency;
$CartObj->PaymentDetails->CustomerIP = '91.220.121.21';
$CartObj->PaymentDetails->PaymentMethod = new stdClass();
//$CartObj->PaymentDetails->PaymentMethod->RecurringEnabled = true;
$CartObj->PaymentDetails->PaymentMethod->RecurringEnabled = false;
$CartObj->PaymentDetails->PaymentMethod->ReturnURL = 'http://secure.avangate.local/z/sofort_return.php';
if ($CartObj->PaymentDetails->Type == 'PREVIOUS_ORDER') {
$CartObj->ExternalReference ='orderbyref_exteranalref' . $CartObj->PaymentDetails->PaymentMethod->RefNo;
} elseif ($CartObj->PaymentDetails->Type == 'PAYPAL') {
$CartObj->ExternalReference ='orderbyref_exteranalref_PAYPAL';
}
echo PHP_EOL . 'Request:' . PHP_EOL . json_encode($CartObj, JSON_PRETTY_PRINT) . PHP_EOL;
try {
$placeOrder = $client->placeOrder($sessionID, $CartObj); // getAvailableCurrencies; getAvailableCountries; getAvailableLanguages; getCheckPaymentDetails
} catch (\SoapFault $e) {
echo $e->getMessage();
}
echo 'Encoded response: ' . PHP_EOL . json_encode($placeOrder, JSON_PRETTY_PRINT) . PHP_EOL;
Response Parameters
Parameter | Type/Description |
---|---|
Object |
|
Object containing order information. |
Rate this article: