Use SOFORT
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 / Direct-Ebanking pay method order on RPC protocol */ function callRPC($Request, $hostUrl, $Debug = false) { $curl = curl_init($hostUrl); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_SSLVERSION, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Accept: application/json', 'Cookie: XDEBUG_SESSION=PHPSTORM' )); $RequestString = json_encode($Request); curl_setopt($curl, CURLOPT_POSTFIELDS, $RequestString); if ($Debug) { var_dump($RequestString); } $ResponseString = curl_exec($curl); if ($Debug) { var_dump($ResponseString); } if (!empty($ResponseString)) { $Response = json_decode($ResponseString); if (isset($Response->result)) { return $Response->result; } var_dump($Response); if (!empty($Response->error)) { var_dump($Request->method, $Response->error); } } else { return null; } } $apiVersion = '6.0'; //$resource = 'orders'; //$host = "http://api.secure.avangate.local/rest/".$apiVersion."/".$resource."/"; $host = "http://api.avangate.local:8081/rpc/" . $apiVersion . "/"; //$host = "http://api.sandbox72.avangate.local/rest/".$apiVersion."/".$resource."/"; // // IdAccount 21478 $merchantCode = "120000589445"; $key = "i9u2+w8%s4^5#8%t)A8?"; $productCode = "BDG8899343FE"; //$productCode = "TANGIBLEP"; // physical product //*/ /*/ IdAccount 21743 (AlexB Migrated Co) $merchantCode = "123456789000"; $key = "F34=P9?1&R0=8)O7O5E="; //$productCode = "JBGL20192"; $productCode = "TINYPRICEPROD"; //*/ /*/ CC1268 merchant @ tests DB $merchantCode = "CC1268"; $key = "SECRET_KEY"; $productCode = "TNGB1USD"; //*/ $date = gmdate('Y-m-d H:i:s'); $string = strlen($merchantCode) . $merchantCode . strlen($date) . $date; //var_dump(gmdate('Y-m-d H:i:s')); //var_dump(date('Y-m-d H:i:s')); die(); $hash = hash_hmac('md5', $string, $key); $i = 1; // counter for api calls // call login $jsonRpcRequest = new stdClass(); $jsonRpcRequest->jsonrpc = '2.0'; $jsonRpcRequest->method = 'login'; $jsonRpcRequest->params = array($merchantCode, $date, $hash); $jsonRpcRequest->id = $i++; $sessionID = callRPC($jsonRpcRequest, $host); //$sessionID = "dad08e7e9a2e2812fbe89e2980b07170c867f8f6"; var_dump("session: ".$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'; } var_dump('Request', json_encode($CartObj)); $jsonRpcRequest = new stdClass(); $jsonRpcRequest->jsonrpc = '2.0'; $jsonRpcRequest->method = 'placeOrder'; $jsonRpcRequest->params = array($sessionID, $CartObj); $jsonRpcRequest->id = $i++; $response = json_encode(callRPC($jsonRpcRequest, $host)); var_dump('Response encoded', $response); $response = json_decode($response); var_dump('Response', $response);
Response Parameters
Parameter | Type/Description |
---|---|
Object |
|
Object containing order information. |