From 3b3374ad4ea0f043c2b4f6225a4f54648be97507 Mon Sep 17 00:00:00 2001 From: schmittrigger Date: Fri, 17 Mar 2017 13:52:26 +0100 Subject: [PATCH] initial commit --- .gitignore | 3 + LICENSE.txt | 21 ++ README.md | 22 ++ composer.json | 22 ++ example.calculationRequest.php | 90 ++++++++ example.configurationRequest.php | 38 ++++ example.confirmationDeliver.php | 99 +++++++++ example.paymentChange.cancellation.php | 69 ++++++ example.paymentChange.changeOrder.php | 60 +++++ example.paymentChange.credit.php | 54 +++++ example.paymentChange.return.php | 70 ++++++ example.paymentConfirm.php | 37 ++++ example.paymentInit.php | 34 +++ example.paymentQuery.php | 104 +++++++++ example.paymentRequest.elv.php | 160 ++++++++++++++ ...aymentRequest.installment.bankTransfer.php | 198 +++++++++++++++++ ...paymentRequest.installment.directDebit.php | 205 ++++++++++++++++++ example.paymentRequest.invoice.php | 190 ++++++++++++++++ example.php | 103 +++++++++ example.profileRequest.php | 33 +++ helper.createTransaction.php | 95 ++++++++ helper.deliverTransaction.php | 7 + ratepay_credentials.php | 4 + 23 files changed, 1718 insertions(+) create mode 100644 .gitignore create mode 100755 LICENSE.txt create mode 100755 README.md create mode 100755 composer.json create mode 100755 example.calculationRequest.php create mode 100755 example.configurationRequest.php create mode 100755 example.confirmationDeliver.php create mode 100755 example.paymentChange.cancellation.php create mode 100755 example.paymentChange.changeOrder.php create mode 100755 example.paymentChange.credit.php create mode 100755 example.paymentChange.return.php create mode 100755 example.paymentConfirm.php create mode 100755 example.paymentInit.php create mode 100755 example.paymentQuery.php create mode 100755 example.paymentRequest.elv.php create mode 100755 example.paymentRequest.installment.bankTransfer.php create mode 100755 example.paymentRequest.installment.directDebit.php create mode 100755 example.paymentRequest.invoice.php create mode 100755 example.php create mode 100755 example.profileRequest.php create mode 100755 helper.createTransaction.php create mode 100755 helper.deliverTransaction.php create mode 100755 ratepay_credentials.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fca36af --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +/vendor/ +composer.lock \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100755 index 0000000..f211519 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 RatePAY GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100755 index 0000000..0aabcd1 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# RatePAY GmbH - PHP SDK +============================================ + +|Module | RatePAY PHP SDK +|------|---------- +|Author | Aarne Welschlau +|Version | `0.9.0` +|Link | http://www.ratepay.com +|Mail | integration@ratepay.com + +### Installation +```bash +composer install +``` + +### Usage + +Find the basic functions of the API library explained in the example files. +The example.php explaines the basic usage of the library. +The other example files (starting with example.paymentInit.php and followed by example.paymentRequest.*.php) describes the further usage in specific cases. + +To run the examples, insert your (received by RatePAY Customer Integration Team) credentials into 'ratepay_credentials.php'. \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100755 index 0000000..d8969ce --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "ratepay/php-sdk", + "description": "RatePAY PHP SDK", + "version": "0.9.0", + "license": "MIT", + "type": "library", + "homepage": "https://dev.ratepay.com", + "support": { + "email": "integration@ratepay.com", + "source": "https://github.com/ratepay/php-sdk" + }, + "authors": [ + { + "name": "Aarne Welschlau", + "email": "aarne.welschlau@ratepay.com" + } + ], + "require": { + "ratepay/php-library": "dev-master" + }, + "minimum-stability": "dev" +} \ No newline at end of file diff --git a/example.calculationRequest.php b/example.calculationRequest.php new file mode 100755 index 0000000..c117cdf --- /dev/null +++ b/example.calculationRequest.php @@ -0,0 +1,90 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ] +]); + +// CalculationRequest provides two types of operation: calculation by time and calculation by rate +// Example: calculation by time +$mbContentTime = new RatePAY\ModelBuilder('Content'); +$mbContentTime->setArray([ + 'InstallmentCalculation' => [ + 'Amount' => 464.95, + 'CalculationTime' => [ + 'Month' => 6 + ] + ] +]); + +$rb = new RatePAY\RequestBuilder(true); // Sandbox mode = true + +// CalculationRequest has to be specified by subtype +$calculationRequest = $rb->callCalculationRequest($mbHead, $mbContentTime)->subtype('calculation-by-time'); + +if (!$calculationRequest->isSuccessful()) die("CalculationRequest not successful"); + +var_dump("Example: calculation by time"); + +var_dump($calculationRequest->getReasonMessage()); // Returns RatePAY (technical) reason message {string} +var_dump($calculationRequest->getResult()); // Returns whole result {array} + +// The CalculationRequest response object provides following methods: +// getPaymentAmount(); // Returns total amount (basket + installment fee) (for PaymentRequest payment section) {float} +// getInstallmentNumber(); // Returns number of rates for installment details (for PaymentRequest payment section) {int} +// getInstallmentAmount(); // Returns rate (for PaymentRequest payment section) {float} +// getLastInstallmentAmount(); // Returns last rate (for PaymentRequest payment section) {float} +// getInterestRate(); // Returns interest rate {float} +// getPaymentFirstday(); // Returns payment firstday {int} + +var_dump($calculationRequest->getPaymentAmount()); +var_dump($calculationRequest->getInstallmentNumber()); +var_dump($calculationRequest->getInstallmentAmount()); +var_dump($calculationRequest->getLastInstallmentAmount()); +var_dump($calculationRequest->getInterestRate()); +var_dump($calculationRequest->getPaymentFirstday()); + + + +// Example: calculation by rate +var_dump("Example: calculation by rate"); + +$mbContentRate = new RatePAY\ModelBuilder('Content'); +$mbContentRate->setArray([ + 'InstallmentCalculation' => [ + 'Amount' => 500, + 'CalculationRate' => [ + 'Rate' => 50 + ] + ] +]); + +$calculationRequest = $rb->callCalculationRequest($mbHead, $mbContentRate)->subtype('calculation-by-rate'); + +var_dump($calculationRequest->getReasonMessage()); +var_dump($calculationRequest->getResult()); + +var_dump($calculationRequest->getPaymentAmount()); +var_dump($calculationRequest->getInstallmentNumber()); +var_dump($calculationRequest->getInstallmentAmount()); +var_dump($calculationRequest->getLastInstallmentAmount()); +var_dump($calculationRequest->getInterestRate()); +var_dump($calculationRequest->getPaymentFirstday()); + + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ \ No newline at end of file diff --git a/example.configurationRequest.php b/example.configurationRequest.php new file mode 100755 index 0000000..511fbb5 --- /dev/null +++ b/example.configurationRequest.php @@ -0,0 +1,38 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ] +]); + +$rb = new RatePAY\RequestBuilder(true); // Sandbox mode = true + +$configurationRequest = $rb->callConfigurationRequest($mbHead); + +if (!$configurationRequest->isSuccessful()) die("ConfigurationRequest not successful"); + +// The ConfigurationRequest response object provides following methods: +// getAllowedMonths(); // Returns list of allowed months {array} @param: order amount {numeric} is optional but recommended +// getMinRate(); // Returns minimum rate {float} +// getMaxRate(order amount); // Returns maximum rate {float} @param: order amount {numeric} is mandatory + +var_dump($configurationRequest->getAllowedMonths()); +var_dump($configurationRequest->getMinRate()); + + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ \ No newline at end of file diff --git a/example.confirmationDeliver.php b/example.confirmationDeliver.php new file mode 100755 index 0000000..3a67628 --- /dev/null +++ b/example.confirmationDeliver.php @@ -0,0 +1,99 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ], + 'TransactionId' => $transactionId +]); + +// Tracking information is optional +$tracking = [ + 'External' => [ + 'Tracking' => [ + 'Id' => "123456", + 'Provider' => 'DHL' + ] + ] +]; +$mbHead->setArray($tracking); + +/* + * The ConfirmationDeliver (CD) requires shipped articles of an order. + * In case of split/partial shipping, multiple CD requests are possible. + * If payment method 'installment' is used, it's recommended to send just one CD after order is completely shipped. + */ +$shoppingBasket = [ + 'ShoppingBasket' => [ + 'Items' => [ + [ + 'Item' => [ + 'Description' => "Test product 1", + 'ArticleNumber' => "ArtNo1", + 'Quantity' => 1, + 'UnitPriceGross' => 300, + 'TaxRate' => 19, + ] + ], [ + 'Item' => [ + 'Description' => "Test product 2", + 'ArticleNumber' => "ArtNo2", + 'Quantity' => 2, + 'UnitPriceGross' => 100, + 'TaxRate' => 19, + 'Discount' => 10 + ] + ] + ], + 'Shipping' => [ + 'Description' => "Shipping costs", + 'UnitPriceGross' => 4.95, + 'TaxRate' => 19, + ], + 'Discount' => [ + 'Description' => "Discount 20 EUR", + 'UnitPriceGross' => 20, + 'TaxRate' => 19, + ] + ] +]; + +// Invoicing information is optional +$invoicing = [ + 'Invoicing' => [ + 'InvoiceId' => "123456", + //'InvoiceDate' => date('Y-m-d\Th:m:s'), + //'DeliveryDate' => date('Y-m-d\Th:m:s'), + 'DueDate' => date('Y-m-d\Th:m:s'), + ] +]; + +$mbContent = new RatePAY\ModelBuilder('Content'); +$mbContent->setArray($shoppingBasket); +$mbContent->setArray($invoicing); + +$confirmationDeliver = $rb->callConfirmationDeliver($mbHead, $mbContent); + +if (!$confirmationDeliver->isSuccessful()) die("ConfirmationDeliver not successful"); + +var_dump("ConfirmationDeliver successful"); + +// ConfirmationDeliver response object provides no specific methods + + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ \ No newline at end of file diff --git a/example.paymentChange.cancellation.php b/example.paymentChange.cancellation.php new file mode 100755 index 0000000..6366903 --- /dev/null +++ b/example.paymentChange.cancellation.php @@ -0,0 +1,69 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ], + 'TransactionId' => $transactionId +]); + +/* + * The PaymentChange Cancellation (PCh) requires cancelled articles of an order. + * It has to be send before the ConfirmationDeliver + * In case of partial cancellation, multiple PCh requests are possible. + */ +$shoppingBasket = [ + 'ShoppingBasket' => [ + 'Items' => [ + [ + 'Item' => [ + 'Description' => "Test product 1", + 'ArticleNumber' => "ArtNo1", + 'Quantity' => 1, + 'UnitPriceGross' => 300, + 'TaxRate' => 19, + ] + ], [ + 'Item' => [ + 'Description' => "Test product 2", + 'ArticleNumber' => "ArtNo2", + 'Quantity' => 2, + 'UnitPriceGross' => 100, + 'TaxRate' => 19, + 'Discount' => 10 + ] + ] + ] + ] +]; + +$mbContent = new RatePAY\ModelBuilder('Content'); +$mbContent->setArray($shoppingBasket); + +// PaymentChange has to be specified by subtype +$pChCancellation = $rb->callPaymentChange($mbHead, $mbContent)->subtype('cancellation'); + +if (!$pChCancellation->isSuccessful()) die("PaymentChange not successful"); + +var_dump("PaymentChange successful"); + +// PaymentChange response object provides no specific methods + + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ \ No newline at end of file diff --git a/example.paymentChange.changeOrder.php b/example.paymentChange.changeOrder.php new file mode 100755 index 0000000..66d69b1 --- /dev/null +++ b/example.paymentChange.changeOrder.php @@ -0,0 +1,60 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ], + 'TransactionId' => $transactionId +]); + +/* + * The PaymentChange Change Order (PCh) requires all articles of an changed order. + * It has to be send after the ConfirmationDeliver + */ +$shoppingBasket = [ + 'ShoppingBasket' => [ + 'Items' => [ + [ + 'Item' => [ + 'Description' => "Different Test product X", + 'ArticleNumber' => "X.123", + 'Quantity' => 2, + 'UnitPriceGross' => 219.95, + 'TaxRate' => 19, + ] + ] + ] + ] +]; + +$mbContent = new RatePAY\ModelBuilder('Content'); +$mbContent->setArray($shoppingBasket); + +// PaymentChange has to be specified by subtype +$pChChangeOrder = $rb->callPaymentChange($mbHead, $mbContent)->subtype('change-order'); + +if (!$pChChangeOrder->isSuccessful()) die("PaymentChange not successful"); + +var_dump("PaymentChange successful"); + +// PaymentChange response object provides no specific methods + + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ \ No newline at end of file diff --git a/example.paymentChange.credit.php b/example.paymentChange.credit.php new file mode 100755 index 0000000..c26d7b1 --- /dev/null +++ b/example.paymentChange.credit.php @@ -0,0 +1,54 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ], + 'TransactionId' => $transactionId +]); + +/* + * The PaymentChange Credit (PCh) requires a discount item. + * It has to be send after the ConfirmationDeliver + */ +$shoppingBasket = [ + 'ShoppingBasket' => [ + 'Discount' => [ + 'Description' => "Goodwill refund", + 'UnitPriceGross' => 20, + 'TaxRate' => 19, + ] + ] +]; + +$mbContent = new RatePAY\ModelBuilder('Content'); +$mbContent->setArray($shoppingBasket); + +// PaymentChange has to be specified by subtype +$pChCredit = $rb->callPaymentChange($mbHead, $mbContent)->subtype('credit'); + +if (!$pChCredit->isSuccessful()) die("PaymentChange not successful"); + +var_dump("PaymentChange successful"); + +// PaymentChange response object provides no specific methods + + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ \ No newline at end of file diff --git a/example.paymentChange.return.php b/example.paymentChange.return.php new file mode 100755 index 0000000..b3f3801 --- /dev/null +++ b/example.paymentChange.return.php @@ -0,0 +1,70 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ], + 'TransactionId' => $transactionId +]); + +/* + * The PaymentChange Return (PCh) requires returned/refunded articles of an order. + * It has to be send after the ConfirmationDeliver + * In case of partial return, multiple PCh requests are possible. + */ +$shoppingBasket = [ + 'ShoppingBasket' => [ + 'Items' => [ + [ + 'Item' => [ + 'Description' => "Test product 1", + 'ArticleNumber' => "ArtNo1", + 'Quantity' => 1, + 'UnitPriceGross' => 300, + 'TaxRate' => 19, + ] + ], [ + 'Item' => [ + 'Description' => "Test product 2", + 'ArticleNumber' => "ArtNo2", + 'Quantity' => 2, + 'UnitPriceGross' => 100, + 'TaxRate' => 19, + 'Discount' => 10 + ] + ] + ] + ] +]; + +$mbContent = new RatePAY\ModelBuilder('Content'); +$mbContent->setArray($shoppingBasket); + +// PaymentChange has to be specified by subtype +$pChReturn = $rb->callPaymentChange($mbHead, $mbContent)->subtype('return'); + +if (!$pChReturn->isSuccessful()) die("PaymentChange not successful"); + +var_dump("PaymentChange successful"); + +// PaymentChange response object provides no specific methods + + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ \ No newline at end of file diff --git a/example.paymentConfirm.php b/example.paymentConfirm.php new file mode 100755 index 0000000..d7dcd33 --- /dev/null +++ b/example.paymentConfirm.php @@ -0,0 +1,37 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ], + 'TransactionId' => $transactionId +]); + +$rb = new RatePAY\RequestBuilder(true); // Sandbox mode = true + +$paymentConfirm = $rb->callPaymentConfirm($mbHead); + +if (!$paymentConfirm->isSuccessful()) die("PaymentConfirm not successful"); + +var_dump("PaymentConfirm successful"); + +// PaymentConfirm response object provides no specific methods + + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ \ No newline at end of file diff --git a/example.paymentInit.php b/example.paymentInit.php new file mode 100755 index 0000000..140f5ea --- /dev/null +++ b/example.paymentInit.php @@ -0,0 +1,34 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ] +]); + +$rb = new RatePAY\RequestBuilder(true); // true == Sandbox mode +$paymentInit = $rb->callPaymentInit($mbArr); + +if (!$paymentInit->isSuccessful()) die("PaymentInit not successful"); + +// PaymentInit response object provides following methods: +// getTransactionId(); // Returns transaction id (unique transaction identifier) {string} + +var_dump($paymentInit->getTransactionId()); + + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ \ No newline at end of file diff --git a/example.paymentQuery.php b/example.paymentQuery.php new file mode 100755 index 0000000..10ceaea --- /dev/null +++ b/example.paymentQuery.php @@ -0,0 +1,104 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ] +]); + +$rb = new RatePAY\RequestBuilder(true); +$paymentInit = $rb->callPaymentInit($mbHead); +if (!$paymentInit->isSuccessful()) die("PaymentInit not successful"); + +// Extending head model with required customer device information +$mbHead->setTransactionId($paymentInit->getTransactionId()); +$mbHead->setCustomerDevice( + $mbHead->CustomerDevice()->setDeviceToken("1234567890") +); + +// The PaymentQuery requires a content model. + +// Building content model +$mbContent = new RatePAY\ModelBuilder('Content'); +$mbContent->setArray([ + 'Customer' => [ + 'Gender' => "f", + 'FirstName' => "Alice", + 'LastName' => "Nobodyknows", + 'DateOfBirth' => "1975-12-17", + 'IpAddress' => "127.0.0.1", + 'Addresses' => [ + [ + 'Address' => [ + 'Type' => "billing", + 'Street' => "Hive Street 12", + 'ZipCode' => "12345", + 'City' => "Raccoon City", + 'CountryCode' => "de", + ] + ] + ], + 'Contacts' => [ + 'Email' => "alice@umbrella.tld", + 'Phone' => [ + 'DirectDial' => "012 3456789" + ], + ], + ], + 'ShoppingBasket' => [ + 'Items' => [ + [ + 'Item' => [ + 'Description' => "Test product 1", + 'ArticleNumber' => "ArtNo1", + 'Quantity' => 1, + 'UnitPriceGross' => 300, + 'TaxRate' => 19, + ] + ], [ + 'Item' => [ + 'Description' => "Test product 2", + 'ArticleNumber' => "ArtNo2", + 'Quantity' => 2, + 'UnitPriceGross' => 100, + 'TaxRate' => 19, + 'Discount' => 10 + ] + ] + ], + 'Shipping' => [ + 'Description' => "Shipping costs", + 'UnitPriceGross' => 4.95, + 'TaxRate' => 19, + ], + 'Discount' => [ + 'Description' => "Discount 20 EUR", + 'UnitPriceGross' => 20, + 'TaxRate' => 19, + ] + ] +]); + +$rb = new RatePAY\RequestBuilder(true); // Sandbox mode = true + +// PaymentQuery has to be specified by subtype (always 'full') +$paymentQuery = $rb->callPaymentQuery($mbHead, $mbContent)->subtype('full'); + +if (!$paymentQuery->isSuccessful()) die("PaymentQuery not successful"); + +// The PaymentQuery response object provides following methods: +// getTransactionId(); // Returns transaction id (unique transaction identifier) {string} +// getAdmittedPaymentMethods(); // Returns which payment methods are admitted for order (array) + +var_dump($paymentQuery->getAdmittedPaymentMethods()); \ No newline at end of file diff --git a/example.paymentRequest.elv.php b/example.paymentRequest.elv.php new file mode 100755 index 0000000..a284cfa --- /dev/null +++ b/example.paymentRequest.elv.php @@ -0,0 +1,160 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ] +]); + +$rb = new RatePAY\RequestBuilder(true); +$paymentInit = $rb->callPaymentInit($mbHead); +if (!$paymentInit->isSuccessful()) die("PaymentInit not successful"); + +// Extending head model with required customer device information +$mbHead->setTransactionId($paymentInit->getTransactionId()); +$mbHead->setCustomerDevice( + $mbHead->CustomerDevice()->setDeviceToken("1234567890") +); +// External commits additional information about customer and order. Is optional. +$mbHead->setArray([ + 'External' => [ + 'MerchantConsumerId' => "1234567", // Customer Id + 'OrderId' => "xyzabc" + //'MerchantConsumerClassification' => "X" + //'ShopLanguage' => "DEU" + //'ReferenceId' => "xyzabc" + ] +]); + +// The PaymentRequest requires a content model. + +// Building content model +$mbContent = new RatePAY\ModelBuilder('Content'); +$contentArr = [ + 'Customer' => [ + 'Gender' => "f", + //'Salutation' => "Mrs.", + //'Title' => "Dr.", + 'FirstName' => "Alice", + //'MiddleName' => "J.", + 'LastName' => "Nobodyknows", + //'NameSuffix' => "Sen.", + 'DateOfBirth' => "1975-12-17", + //'Nationality' => "DE", + 'IpAddress' => "127.0.0.1", + 'Addresses' => [ + [ + 'Address' => [ + 'Type' => "billing", + 'Street' => "Hive Street 12", + //'StreetAdditional' => "SubLevel 27", + //'StreetNumber' => "12", + 'ZipCode' => "12345", + 'City' => "Raccoon City", + 'CountryCode' => "de", + ] + ], [ + 'Address' => [ + 'Type' => "delivery", + //'Salutation' => "Mrs.", + 'FirstName' => "Alice", + 'LastName' => "Nobodyknows", + //'Company' => "Umbrella Corp.", + 'Street' => "Hive Street 12", + //'StreetAdditional' => "SubLevel 27", + //'StreetNumber' => "12", + 'ZipCode' => "12345", + 'City' => "Raccoon City", + 'CountryCode' => "de", + ] + ] + ], + 'Contacts' => [ + 'Email' => "alice@umbrella.tld", + //'Mobile' => "0123 4567890", + 'Phone' => [ + //'AreaCode' => "012", + 'DirectDial' => "012 3456789" + ], + //'Fax' => "012 3456777", + ], + 'BankAccount' => [ // In case of payment method 'elv' + 'Owner' => "Alice Nobodyknows", + 'Iban' => "AT123456789012345678", + //'BankName' => "Umbrella Finance", + //'BankAccountNumber' => "1234567890", + //'BankCode' => "12345678", + ], + // 'CompanyName' => "Umbrella Corp.", + // 'CompanyType' => "AG", + // 'VatId' => "DE123456789", + // 'CompanyId' => "HRB 123456X", + // 'RegistryLocation' => "Raccoon City", + // 'Homepage' => "http://www.umbrellacorporation.tld", + ], + 'ShoppingBasket' => [ + 'Items' => [ + [ + 'Item' => [ + 'Description' => "Test product 1", + 'ArticleNumber' => "ArtNo1", + //'UniqueArticleNumber' => "ArtNo1-variation123", + 'Quantity' => 1, + 'UnitPriceGross' => 300, + 'TaxRate' => 19, + //'Category' => "Additional information about the product" + //'DescriptionAddition' => "Additional information about the product" + ] + ], [ + 'Item' => [ + 'Description' => "Test product 2", + 'ArticleNumber' => "ArtNo2", + 'Quantity' => 2, + 'UnitPriceGross' => 100, + 'TaxRate' => 19, + 'Discount' => 10 + ] + ] + ], + 'Shipping' => [ + 'Description' => "Shipping costs", + 'UnitPriceGross' => 4.95, + 'TaxRate' => 19, + //'DescriptionAddition' => "Additional information about the shipping" + ], + 'Discount' => [ + 'Description' => "Discount 20 EUR", + 'UnitPriceGross' => 20, + 'TaxRate' => 19, + //'DescriptionAddition' => "Additional information about the discount" + ] + ], + 'Payment' => [ + 'Method' => "elv", // "invoice", "installment", "elv", "prepayment" + 'Amount' => 464.95 + ] +]; +$mbContent->setArray($contentArr); + +$rb = new RatePAY\RequestBuilder(true); // Sandbox mode = true +$paymentRequest = $rb->callPaymentRequest($mbHead, $mbContent); + +if (!$paymentRequest->isSuccessful()) die("PaymentRequest not successful"); + +// The PaymentRequest response object provides following methods: +// getTransactionId(); // Returns transaction id (unique transaction identifier) {string} +// isRetryAdmitted(); // Returns whether retry is admitted {boolean} +// getCustomerMessage(); // Returns customer message {string} + +var_dump($paymentRequest->getTransactionId()); diff --git a/example.paymentRequest.installment.bankTransfer.php b/example.paymentRequest.installment.bankTransfer.php new file mode 100755 index 0000000..b034133 --- /dev/null +++ b/example.paymentRequest.installment.bankTransfer.php @@ -0,0 +1,198 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ] +]); + +$rb = new RatePAY\RequestBuilder(true); +$paymentInit = $rb->callPaymentInit($mbHead); +if (!$paymentInit->isSuccessful()) die("PaymentInit not successful"); + +// Extending head model with required customer device information +$mbHead->setTransactionId($paymentInit->getTransactionId()); +$mbHead->setCustomerDevice( + $mbHead->CustomerDevice()->setDeviceToken("1234567890") +); +// External commits additional information about customer and order. Is optional. +$mbHead->setArray([ + 'External' => [ + 'MerchantConsumerId' => "1234567", // Customer Id + 'OrderId' => "xyzabc" + //'MerchantConsumerClassification' => "X" + //'ShopLanguage' => "DEU" + //'ReferenceId' => "xyzabc" + ] +]); + +// The PaymentRequest requires a content model. + +// Building content model +$mbContent = new RatePAY\ModelBuilder('Content'); +$contentArr = [ + 'Customer' => [ + 'Gender' => "f", + //'Salutation' => "Mrs.", + //'Title' => "Dr.", + 'FirstName' => "Alice", + //'MiddleName' => "J.", + 'LastName' => "Nobodyknows", + //'NameSuffix' => "Sen.", + 'DateOfBirth' => "1975-12-17", + //'Nationality' => "DE", + 'IpAddress' => "127.0.0.1", + 'Addresses' => [ + [ + 'Address' => [ + 'Type' => "billing", + 'Street' => "Hive Street 12", + //'StreetAdditional' => "SubLevel 27", + //'StreetNumber' => "12", + 'ZipCode' => "12345", + 'City' => "Raccoon City", + 'CountryCode' => "de", + ] + ], [ + 'Address' => [ + 'Type' => "delivery", + //'Salutation' => "Mrs.", + 'FirstName' => "Alice", + 'LastName' => "Nobodyknows", + //'Company' => "Umbrella Corp.", + 'Street' => "Hive Street 12", + //'StreetAdditional' => "SubLevel 27", + //'StreetNumber' => "12", + 'ZipCode' => "12345", + 'City' => "Raccoon City", + 'CountryCode' => "de", + ] + ] + ], + 'Contacts' => [ + 'Email' => "alice@umbrella.tld", + //'Mobile' => "0123 4567890", + 'Phone' => [ + //'AreaCode' => "012", + 'DirectDial' => "012 3456789" + ], + //'Fax' => "012 3456777", + ], + // 'CompanyName' => "Umbrella Corp.", + // 'CompanyType' => "AG", + // 'VatId' => "DE123456789", + // 'CompanyId' => "HRB 123456X", + // 'RegistryLocation' => "Raccoon City", + // 'Homepage' => "http://www.umbrellacorporation.tld", + ], + 'ShoppingBasket' => [ + 'Items' => [ + [ + 'Item' => [ + 'Description' => "Test product 1", + 'ArticleNumber' => "ArtNo1", + //'UniqueArticleNumber' => "ArtNo1-variation123", + 'Quantity' => 1, + 'UnitPriceGross' => 300, + 'TaxRate' => 19, + //'Category' => "Additional information about the product" + //'DescriptionAddition' => "Additional information about the product" + ] + ], [ + 'Item' => [ + 'Description' => "Test product 2", + 'ArticleNumber' => "ArtNo", + 'Quantity' => 2, + 'UnitPriceGross' => 100, + 'TaxRate' => 19, + 'Discount' => 10 + ] + ] + ], + 'Shipping' => [ + 'Description' => "Shipping costs", + 'UnitPriceGross' => 4.95, + 'TaxRate' => 19, + //'DescriptionAddition' => "Additional information about the shipping" + ], + 'Discount' => [ + 'Description' => "Discount 20 EUR", + 'UnitPriceGross' => 20, + 'TaxRate' => 19, + //'DescriptionAddition' => "Additional information about the discount" + ] + ], + 'Payment' => [ + 'Method' => "installment", + 'Amount' => 483.25, + 'InstallmentDetails' => [ + 'InstallmentNumber' => 6, + 'InstallmentAmount' => 80.55, + 'LastInstallmentAmount' => 80.5, + 'InterestRate' => 9.8, + 'PaymentFirstday' => 28, + ], + 'DebitPayType' => "BANK-TRANSFER" + ] +]; +$mbContent->setArray($contentArr); + +$rb = new RatePAY\RequestBuilder(true); // Sandbox mode = true +$paymentRequest = $rb->callPaymentRequest($mbHead, $mbContent); + +if (!$paymentRequest->isSuccessful()) die("PaymentRequest not successful"); + +// The PaymentRequest response object provides following methods: +// getTransactionId(); // Returns transaction id (unique transaction identifier) {string} +// isRetryAdmitted(); // Returns whether retry is admitted {boolean} +// getCustomerMessage(); // Returns customer message {string} + +var_dump($paymentRequest->getTransactionId()); +// If the order gets rejected by RatePAY because of invalid inputs (like invalid zip code or iban), a retry of order is allowed. +var_dump($paymentRequest->isRetryAdmitted()); +// If retry of order is allowed, the there will be a customer message with further information. +var_dump($paymentRequest->getCustomerMessage()); + + +// Example of rejection with allowed retry and customer message: + +$mbHead = new RatePAY\ModelBuilder(); +$mbHead->setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ] +]); + +$paymentInit = $rb->callPaymentInit($mbHead); + +$mbHead->setTransactionId($paymentInit->getTransactionId()); +$mbHead->setCustomerDevice( + $mbHead->CustomerDevice()->setDeviceToken("1234567890") +); + +$contentArr['Customer']['Addresses'][0]['Address']['ZipCode'] = "1234"; +$mbContent->setArray($contentArr); + +$rb = new RatePAY\RequestBuilder(true); +$paymentRequest = $rb->callPaymentRequest($mbHead, $mbContent); + +var_dump($paymentRequest->isRetryAdmitted()); +var_dump($paymentRequest->getCustomerMessage()); + + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ \ No newline at end of file diff --git a/example.paymentRequest.installment.directDebit.php b/example.paymentRequest.installment.directDebit.php new file mode 100755 index 0000000..31da6a8 --- /dev/null +++ b/example.paymentRequest.installment.directDebit.php @@ -0,0 +1,205 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ] +]); + +$rb = new RatePAY\RequestBuilder(true); +$paymentInit = $rb->callPaymentInit($mbHead); +if (!$paymentInit->isSuccessful()) die("PaymentInit not successful"); + +// Extending head model with required customer device information +$mbHead->setTransactionId($paymentInit->getTransactionId()); +$mbHead->setCustomerDevice( + $mbHead->CustomerDevice()->setDeviceToken("1234567890") +); +// External commits additional information about customer and order. Is optional. +$mbHead->setArray([ + 'External' => [ + 'MerchantConsumerId' => "1234567", // Customer Id + 'OrderId' => "xyzabc" + //'MerchantConsumerClassification' => "X" + //'ShopLanguage' => "DEU" + //'ReferenceId' => "xyzabc" + ] +]); + +// The PaymentRequest requires a content model. + +// Building content model +$mbContent = new RatePAY\ModelBuilder('Content'); +$contentArr = [ + 'Customer' => [ + 'Gender' => "f", + //'Salutation' => "Mrs.", + //'Title' => "Dr.", + 'FirstName' => "Alice", + //'MiddleName' => "J.", + 'LastName' => "Nobodyknows", + //'NameSuffix' => "Sen.", + 'DateOfBirth' => "1975-12-17", + //'Nationality' => "DE", + 'IpAddress' => "127.0.0.1", + 'Addresses' => [ + [ + 'Address' => [ + 'Type' => "billing", + 'Street' => "Hive Street 12", + //'StreetAdditional' => "SubLevel 27", + //'StreetNumber' => "12", + 'ZipCode' => "12345", + 'City' => "Raccoon City", + 'CountryCode' => "de", + ] + ], [ + 'Address' => [ + 'Type' => "delivery", + //'Salutation' => "Mrs.", + 'FirstName' => "Alice", + 'LastName' => "Nobodyknows", + //'Company' => "Umbrella Corp.", + 'Street' => "Hive Street 12", + //'StreetAdditional' => "SubLevel 27", + //'StreetNumber' => "12", + 'ZipCode' => "12345", + 'City' => "Raccoon City", + 'CountryCode' => "de", + ] + ] + ], + 'Contacts' => [ + 'Email' => "alice@umbrella.tld", + //'Mobile' => "0123 4567890", + 'Phone' => [ + //'AreaCode' => "012", + 'DirectDial' => "012 3456789" + ], + //'Fax' => "012 3456777", + ], + 'BankAccount' => [ // In case of payment method 'elv' + 'Owner' => "Alice Nobodyknows", + 'Iban' => "AT123456789012345678", + //'BankName' => "Umbrella Finance", + //'BankAccountNumber' => "1234567890", + //'BankCode' => "12345678", + ], + // 'CompanyName' => "Umbrella Corp.", + // 'CompanyType' => "AG", + // 'VatId' => "DE123456789", + // 'CompanyId' => "HRB 123456X", + // 'RegistryLocation' => "Raccoon City", + // 'Homepage' => "http://www.umbrellacorporation.tld", + ], + 'ShoppingBasket' => [ + 'Items' => [ + [ + 'Item' => [ + 'Description' => "Test product 1", + 'ArticleNumber' => "ArtNo1", + //'UniqueArticleNumber' => "ArtNo1-variation123", + 'Quantity' => 1, + 'UnitPriceGross' => 300, + 'TaxRate' => 19, + //'Category' => "Additional information about the product" + //'DescriptionAddition' => "Additional information about the product" + ] + ], [ + 'Item' => [ + 'Description' => "Test product 2", + 'ArticleNumber' => "ArtNo", + 'Quantity' => 2, + 'UnitPriceGross' => 100, + 'TaxRate' => 19, + 'Discount' => 10 + ] + ] + ], + 'Shipping' => [ + 'Description' => "Shipping costs", + 'UnitPriceGross' => 4.95, + 'TaxRate' => 19, + //'DescriptionAddition' => "Additional information about the shipping" + ], + 'Discount' => [ + 'Description' => "Discount 20 EUR", + 'UnitPriceGross' => 20, + 'TaxRate' => 19, + //'DescriptionAddition' => "Additional information about the discount" + ] + ], + 'Payment' => [ + 'Method' => "installment", + 'Amount' => 483.25, + 'InstallmentDetails' => [ + 'InstallmentNumber' => 6, + 'InstallmentAmount' => 80.55, + 'LastInstallmentAmount' => 80.5, + 'InterestRate' => 9.8, + 'PaymentFirstday' => 2, + ], + 'DebitPayType' => "DIRECT-DEBIT" + ] +]; +$mbContent->setArray($contentArr); + +$rb = new RatePAY\RequestBuilder(true); // Sandbox mode = true +$paymentRequest = $rb->callPaymentRequest($mbHead, $mbContent); + +if (!$paymentRequest->isSuccessful()) die("PaymentRequest not successful"); + +// The PaymentRequest response object provides following methods: +// getTransactionId(); // Returns transaction id (unique transaction identifier) {string} +// isRetryAdmitted(); // Returns whether retry is admitted {boolean} +// getCustomerMessage(); // Returns customer message {string} + +var_dump($paymentRequest->getTransactionId()); +// If the order gets rejected by RatePAY because of invalid inputs (like invalid zip code or iban), a retry of order is allowed. +var_dump($paymentRequest->isRetryAdmitted()); +// If retry of order is allowed, the there will be a customer message with further information. +var_dump($paymentRequest->getCustomerMessage()); + + +// Example of rejection with allowed retry and customer message: + +$mbHead = new RatePAY\ModelBuilder(); +$mbHead->setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ] +]); + +$paymentInit = $rb->callPaymentInit($mbHead); + +$mbHead->setTransactionId($paymentInit->getTransactionId()); +$mbHead->setCustomerDevice( + $mbHead->CustomerDevice()->setDeviceToken("1234567890") +); + +$contentArr['Customer']['Addresses'][0]['Address']['ZipCode'] = "1234"; +$mbContent->setArray($contentArr); + +$rb = new RatePAY\RequestBuilder(true); +$paymentRequest = $rb->callPaymentRequest($mbHead, $mbContent); + +var_dump($paymentRequest->isRetryAdmitted()); +var_dump($paymentRequest->getCustomerMessage()); + + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ \ No newline at end of file diff --git a/example.paymentRequest.invoice.php b/example.paymentRequest.invoice.php new file mode 100755 index 0000000..0b4badc --- /dev/null +++ b/example.paymentRequest.invoice.php @@ -0,0 +1,190 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ] +]); + +$rb = new RatePAY\RequestBuilder(true); +$paymentInit = $rb->callPaymentInit($mbHead); +if (!$paymentInit->isSuccessful()) die("PaymentInit not successful"); + +// Extending head model with required customer device information +$mbHead->setTransactionId($paymentInit->getTransactionId()); +$mbHead->setCustomerDevice( + $mbHead->CustomerDevice()->setDeviceToken("1234567890") +); +// External commits additional information about customer and order. Is optional. +$mbHead->setArray([ + 'External' => [ + 'MerchantConsumerId' => "1234567", // Customer Id + 'OrderId' => "xyzabc" + //'MerchantConsumerClassification' => "X" + //'ShopLanguage' => "DEU" + //'ReferenceId' => "xyzabc" + ] +]); + +// The PaymentRequest requires a content model. + +// Building content model +$mbContent = new RatePAY\ModelBuilder('Content'); +$contentArr = [ + 'Customer' => [ + 'Gender' => "f", + //'Salutation' => "Mrs.", + //'Title' => "Dr.", + 'FirstName' => "Alice", + //'MiddleName' => "J.", + 'LastName' => "Nobodyknows", + //'NameSuffix' => "Sen.", + 'DateOfBirth' => "1975-12-17", + //'Nationality' => "DE", + 'IpAddress' => "127.0.0.1", + 'Addresses' => [ + [ + 'Address' => [ + 'Type' => "billing", + 'Street' => "Hive Street 12", + //'StreetAdditional' => "SubLevel 27", + //'StreetNumber' => "12", + 'ZipCode' => "12345", + 'City' => "Raccoon City", + 'CountryCode' => "de", + ] + ], [ + 'Address' => [ + 'Type' => "delivery", + //'Salutation' => "Mrs.", + 'FirstName' => "Alice", + 'LastName' => "Nobodyknows", + //'Company' => "Umbrella Corp.", + 'Street' => "Hive Street 12", + //'StreetAdditional' => "SubLevel 27", + //'StreetNumber' => "12", + 'ZipCode' => "12345", + 'City' => "Raccoon City", + 'CountryCode' => "de", + ] + ] + ], + 'Contacts' => [ + 'Email' => "alice@umbrella.tld", + //'Mobile' => "0123 4567890", + 'Phone' => [ + //'AreaCode' => "012", + 'DirectDial' => "012 3456789" + ], + //'Fax' => "012 3456777", + ], + // 'CompanyName' => "Umbrella Corp.", + // 'CompanyType' => "AG", + // 'VatId' => "DE123456789", + // 'CompanyId' => "HRB 123456X", + // 'RegistryLocation' => "Raccoon City", + // 'Homepage' => "http://www.umbrellacorporation.tld", + ], + 'ShoppingBasket' => [ + 'Items' => [ + [ + 'Item' => [ + 'Description' => "Test product 1", + 'ArticleNumber' => "ArtNo1", + //'UniqueArticleNumber' => "ArtNo1-variation123", + 'Quantity' => 1, + 'UnitPriceGross' => 300, + 'TaxRate' => 19, + //'Category' => "Additional information about the product" + //'DescriptionAddition' => "Additional information about the product" + ] + ], [ + 'Item' => [ + 'Description' => "Test product 2", + 'ArticleNumber' => "ArtNo", + 'Quantity' => 2, + 'UnitPriceGross' => 100, + 'TaxRate' => 19, + 'Discount' => 10 + ] + ] + ], + 'Shipping' => [ + 'Description' => "Shipping costs", + 'UnitPriceGross' => 4.95, + 'TaxRate' => 19, + //'DescriptionAddition' => "Additional information about the shipping" + ], + 'Discount' => [ + 'Description' => "Discount 20 EUR", + 'UnitPriceGross' => 20, + 'TaxRate' => 19, + //'DescriptionAddition' => "Additional information about the discount" + ] + ], + 'Payment' => [ + 'Method' => "invoice", // "installment", "elv", "prepayment" + 'Amount' => 464.95 + ] +]; +$mbContent->setArray($contentArr); + +$rb = new RatePAY\RequestBuilder(true); // Sandbox mode = true +$paymentRequest = $rb->callPaymentRequest($mbHead, $mbContent); + +if (!$paymentRequest->isSuccessful()) die("PaymentRequest not successful"); + +// The PaymentRequest response object provides following methods: +// getTransactionId(); // Returns transaction id (unique transaction identifier) {string} +// isRetryAdmitted(); // Returns whether retry is admitted {boolean} +// getCustomerMessage(); // Returns customer message {string} + +var_dump($paymentRequest->getTransactionId()); +// If the order gets rejected by RatePAY because of invalid inputs (like invalid zip code or iban), a retry of order is allowed. +var_dump($paymentRequest->isRetryAdmitted()); +// If retry of order is allowed, the there will be a customer message with further information. +var_dump($paymentRequest->getCustomerMessage()); + + +// Example of rejection with allowed retry and customer message: + +$mbHead = new RatePAY\ModelBuilder(); +$mbHead->setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ] +]); + +$paymentInit = $rb->callPaymentInit($mbHead); + +$mbHead->setTransactionId($paymentInit->getTransactionId()); +$mbHead->setCustomerDevice( + $mbHead->CustomerDevice()->setDeviceToken("1234567890") +); + +$contentArr['Customer']['Addresses'][0]['Address']['ZipCode'] = "1234"; +$mbContent->setArray($contentArr); + +$rb = new RatePAY\RequestBuilder(true); +$paymentRequest = $rb->callPaymentRequest($mbHead, $mbContent); + +var_dump($paymentRequest->isRetryAdmitted()); +var_dump($paymentRequest->getCustomerMessage()); + + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ \ No newline at end of file diff --git a/example.php b/example.php new file mode 100755 index 0000000..c0578f2 --- /dev/null +++ b/example.php @@ -0,0 +1,103 @@ +setSystemId("Example") + ->setCredential( + (new RatePAY\Model\Request\SubModel\Head\Credential) + ->setProfileId(PROFILE_ID) + ->setSecuritycode(SECURITYCODE) + ); + +// Using the ModelBuilder makes the instantiation a lot easier. +$mb = new RatePAY\ModelBuilder('Head'); +$mb->setSystemId("Example") + ->setCredential( + $mb->Credential() + ->setProfileId(PROFILE_ID) + ->setSecuritycode(SECURITYCODE) + ); + +// A alternative way to set the request model is to commit a multidimensional array. +// The instantiation of lower submodels is done automatically. +// This way ensures a higher performance and is RECOMMENDED to use. +$mbArr = new RatePAY\ModelBuilder('Head'); +$mbArr->setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ], + 'Meta' => [ + 'Systems' => [ + 'System' => [ + 'Name' => 'Magento 2' + ] + ] + ] +]); + +// It's also possible to commit the information as JSON +$mbJson = new RatePAY\ModelBuilder(); +$mbJson->setJson('{ + "SystemId": "Example", + "Credential" : { + "ProfileId" : "' . PROFILE_ID . '", + "Securitycode" : "' . SECURITYCODE . '" + } +}'); + +// Initiation of generic RequestBuilder object. +$rb = new RatePAY\RequestBuilder(true); // true == Sandbox mode + +// $rb->getAvailableRequests(); // Returns a list of all available RatePAY gateway requests (covered by library) {array} + +// Call a request by the example of PaymentInit +$paymentInit = $rb->callPaymentInit($mbArr); // Initializes transaction + +// After the request is called the return object provides several common response methods +// isSuccessful(); // Returns whether request was successful {boolean} +// getRequestRaw(); // Returns request as xml (e.g. for logging) {string} +// getResponseRaw(); // Returns response as xml (e.g. for logging) {string} +// getRequestXmlElement(); // Returns request as object {SimpleXMLElement} +// getResponseXmlElement(); // Returns response as object {SimpleXMLElement} +// getResponseTime(); // Returns response time in seconds {float} +// getStatusCode(); // Returns RatePAY status code {string} +// getStatusMessage(); // Returns RatePAY status message {string} +// getReasonCode(); // Returns RatePAY reason code {integer} +// getReasonMessage(); // Returns RatePAY reason message {string} +// getResultCode(); // Returns RatePAY result code {integer} +// getResultMessage(); // Returns RatePAY result message {string} +// getResult(); // Returns whole result {array} + +var_dump($paymentInit->isSuccessful()); +var_dump($paymentInit->getRequestRaw()); +var_dump($paymentInit->getResponseRaw()); +var_dump($paymentInit->getResponseTime()); +var_dump($paymentInit->getStatusCode()); +var_dump($paymentInit->getStatusMessage()); +var_dump($paymentInit->getReasonCode()); +var_dump($paymentInit->getReasonMessage()); +var_dump($paymentInit->getResultCode()); +var_dump($paymentInit->getResultMessage()); +var_dump($paymentInit->getResult()); + +// Depending on the different request types, there are special response methods +// In case of PaymentInit there are following methods: +// getTransactionId(); // Returns transaction id (unique transaction identifier) {string} + +var_dump($paymentInit->getTransactionId()); // Returns transaction id (unique transaction identifier) {string} + + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ \ No newline at end of file diff --git a/example.profileRequest.php b/example.profileRequest.php new file mode 100755 index 0000000..26f0b52 --- /dev/null +++ b/example.profileRequest.php @@ -0,0 +1,33 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ] +]); + +$rb = new RatePAY\RequestBuilder(true); // Sandbox mode = true + +$profileRequest = $rb->callProfileRequest($mbHead); + +if (!$profileRequest->isSuccessful()) die("ConfigurationRequest not successful"); + +var_dump($profileRequest->getResult()); + +// The ProfileRequest response object provides no specific methods + +/********************************************************************************************************************************* + * The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. * + *********************************************************************************************************************************/ diff --git a/helper.createTransaction.php b/helper.createTransaction.php new file mode 100755 index 0000000..c604c29 --- /dev/null +++ b/helper.createTransaction.php @@ -0,0 +1,95 @@ +setArray([ + 'SystemId' => "Example", + 'Credential' => [ + 'ProfileId' => PROFILE_ID, + 'Securitycode' => SECURITYCODE + ], +]); + +$rb = new RatePAY\RequestBuilder(true); +$paymentInit = $rb->callPaymentInit($mbHead); +if (!$paymentInit->isSuccessful()) die("PaymentInit not successful"); + +$transactionId = $paymentInit->getTransactionId(); + +$mbHead->setTransactionId($transactionId); +$mbHead->setCustomerDevice( + $mbHead->CustomerDevice()->setDeviceToken("1234567890") +); + +$mbContent = new RatePAY\ModelBuilder('Content'); +$mbContent->setArray([ + 'Customer' => [ + 'Gender' => "f", + 'FirstName' => "Alice", + 'LastName' => "Nobodyknows", + 'DateOfBirth' => "1975-12-17", + 'IpAddress' => "127.0.0.1", + 'Addresses' => [ + [ + 'Address' => [ + 'Type' => "billing", + 'Street' => "Hive Street 12", + 'ZipCode' => "12345", + 'City' => "Raccoon City", + 'CountryCode' => "de", + ] + ] + ], + 'Contacts' => [ + 'Email' => "alice@umbrella.tld", + 'Phone' => [ + 'DirectDial' => "012 3456789" + ], + ], + ], + 'ShoppingBasket' => [ + 'Items' => [ + [ + 'Item' => [ + 'Description' => "Test product 1", + 'ArticleNumber' => "ArtNo1", + 'Quantity' => 1, + 'UnitPriceGross' => 300, + 'TaxRate' => 19, + ] + ], [ + 'Item' => [ + 'Description' => "Test product 2", + 'ArticleNumber' => "ArtNo2", + 'Quantity' => 2, + 'UnitPriceGross' => 100, + 'TaxRate' => 19, + 'Discount' => 10 + ] + ] + ], + 'Shipping' => [ + 'Description' => "Shipping costs", + 'UnitPriceGross' => 4.95, + 'TaxRate' => 19, + ], + 'Discount' => [ + 'Description' => "Discount 20 EUR", + 'UnitPriceGross' => 20, + 'TaxRate' => 19, + ] + ], + 'Payment' => [ + 'Method' => "invoice", + 'Amount' => 464.95 + ] +]); + +$rb = new RatePAY\RequestBuilder(true); +$paymentRequest = $rb->callPaymentRequest($mbHead, $mbContent); +if (!$paymentRequest->isSuccessful()) die("PaymentRequest not successful"); \ No newline at end of file diff --git a/helper.deliverTransaction.php b/helper.deliverTransaction.php new file mode 100755 index 0000000..c4dff8c --- /dev/null +++ b/helper.deliverTransaction.php @@ -0,0 +1,7 @@ +callConfirmationDeliver($mbHead, $mbContent); + +if (!$paymentInit->isSuccessful()) die("ConfirmationDeliver not successful"); \ No newline at end of file diff --git a/ratepay_credentials.php b/ratepay_credentials.php new file mode 100755 index 0000000..142b4c1 --- /dev/null +++ b/ratepay_credentials.php @@ -0,0 +1,4 @@ +