Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rpWelschlau committed Mar 17, 2017
0 parents commit 3b3374a
Show file tree
Hide file tree
Showing 23 changed files with 1,718 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
/vendor/
composer.lock
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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'.
22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
90 changes: 90 additions & 0 deletions example.calculationRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

require __DIR__ . '/vendor/autoload.php';

require_once "ratepay_credentials.php";

/**********************************************************
* The CalculationRequest the installment configuration *
**********************************************************/

// CalculationRequest needs 'head' and 'content'
$mbHead = new RatePAY\ModelBuilder();
$mbHead->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. *
*********************************************************************************************************************************/
38 changes: 38 additions & 0 deletions example.configurationRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

require __DIR__ . '/vendor/autoload.php';

require_once "ratepay_credentials.php";

/**********************************************************
* The ConfigurationRequest the installment configuration *
**********************************************************/

// ConfigurationRequest needs 'head' only
$mbHead = new RatePAY\ModelBuilder();
$mbHead->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. *
*********************************************************************************************************************************/
99 changes: 99 additions & 0 deletions example.confirmationDeliver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

require __DIR__ . '/vendor/autoload.php';

require_once "ratepay_credentials.php";

require_once "helper.createTransaction.php"; // Opens new transaction to handle

/**********************************************
* The ConfirmationDeliver captures the order *
**********************************************/

$mbHead = new RatePAY\ModelBuilder('head');
$mbHead->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. *
*********************************************************************************************************************************/
69 changes: 69 additions & 0 deletions example.paymentChange.cancellation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

require __DIR__ . '/vendor/autoload.php';

require_once "ratepay_credentials.php";

require_once "helper.createTransaction.php"; // Opens new transaction to handle

/************************************************************
* The PaymentChange alters order details (shopping basket) *
* The subtype Cancellation commits all canceled articles *
************************************************************/

$mbHead = new RatePAY\ModelBuilder('head');
$mbHead->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. *
*********************************************************************************************************************************/
Loading

0 comments on commit 3b3374a

Please sign in to comment.