Skip to content

Commit

Permalink
clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob committed Nov 29, 2016
0 parents commit 8f7395f
Show file tree
Hide file tree
Showing 26 changed files with 2,696 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
/vendor
/composer.lock
/doc
/doc.generate.sh
INTERNAL
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 CardGate B.V.

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.
40 changes: 40 additions & 0 deletions README.mdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
![CardGate](https://cdn.curopayments.net/thumb/200/logos/cardgate.png)

# CardGate API client library for PHP #

[![Total Downloads](https://img.shields.io/packagist/dt/cardgate/cardgate-clientlib-php.svg)](https://packagist.org/packages/cardgate/cardgate-clientlib-php)
[![Latest Version](https://img.shields.io/packagist/v/cardgate/cardgate-clientlib-php.svg)](https://github.com/cardgate/cardgate-clientlib-php/releases)

## Installation ##

![CardGate API](https://cdn.curopayments.net/thumb/50/logos/cardgate.api.png)

The CardGate API client library is installed via [Composer](http://getcomposer.org/). To install, simply add it
to your `composer.json` file:

```json
{
"require": {
"cardgate/cardgate-clientlib-php": "~1.0.0"
}
}
```

And run composer to update your dependencies:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

You may also git clone or [download the files manually](https://github.com/cardgate/cardgate-clientlib-php/releases), and include the client library in your project.

## Basic Usage ##

```php
cardgate\api\Autoloader::register();
$oCardGate = new cardgate\api\Client( 1, '<merchant key>', TRUE );
```

## Support ##

If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/cardgate/cardgate-clientlib-php/issues) or
contact us at [tech@cardgate.com](mailto:tech@cardgate.com?subject=CardGate%20API%20client%20library%20for%20PHP%20Support).
31 changes: 31 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "cardgate/cardgate-clientlib-php",
"description": "CardGate API client library for PHP",
"homepage": "https://github.com/cardgate/cardgate-clientlib-php",
"license": "MIT",
"authors": [
{
"name": "CardGate",
"email": "tech@cardgate.com"
},
{
"name": "CardGate",
"homepage": "https://www.cardgate.com"
}
],
"keywords": [
"cardgate", "secure", "payment", "ideal", "bancontact", "sofort", "sofortbanking", "banktransfer", "paypal",
"afterpay", "bitcoin", "directdebit"
],
"require" : {
"php": ">=5.3"
},
"require-dev": {
"phpunit/phpunit": "^3.7 || ^4.8 || ^5.4"
},
"autoload": {
"psr-4": {
"cardgate\\api\\": "src/"
}
}
}
82 changes: 82 additions & 0 deletions examples/1-payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
try {

include 'init.php';

$oTransaction = $oCardGate->transactions()->create( $iSiteId, 660596, 'EUR' );

// Configure payment option.
if ( ! empty( $_POST['option'] ) ) {
$oTransaction->setPaymentMethod( $oCardGate->methods()->get( $_POST['option'] ) );

// Configure
if ( 'ideal' == $_POST['option'] ) {
if ( empty( $_POST['issuer'] ) ) {
header( 'Location: 2-payment-ideal.php' );
exit;
} else {
$oTransaction->setIssuer( $_POST['issuer'] );
}
}
} else {
$oTransaction->setPaymentMethod( cardgate\api\Method::IDEAL );
}

// Configure customer.
$oCustomer = $oTransaction->getCustomer();
$oCustomer->address()->setFirstName( 'John' );
$oCustomer->address()->setInitials( 'J.A.N.' );
$oCustomer->address()->setLastName( 'Doe' );
$oCustomer->address()->setAddress( 'Test Avenue 33' );
$oCustomer->address()->setZipCode( '34342' );
$oCustomer->address()->setCity( 'Minneapolis' );
$oCustomer->address()->setCountry( 'US' );
$oCustomer->shippingAddress()->setFirstName( 'Judy' );
$oCustomer->shippingAddress()->setInitials( 'J.' );
$oCustomer->shippingAddress()->setLastName( 'Doe' );
$oCustomer->shippingAddress()->setAddress( 'Trialstreet 1334' );
$oCustomer->shippingAddress()->setZipCode( '77377' );
$oCustomer->shippingAddress()->setCity( 'Chicago' );
$oCustomer->shippingAddress()->setCountry( 'US' );

// Configure cart.
$oCart = $oTransaction->getCart();
$oItem = $oCart->addItem( \cardgate\api\Item::TYPE_PRODUCT, 'AA21484', 'iMac 27"', 3, 219999, 'http://www.apple.com/imac/' );
$oItem = $oCart->addItem( \cardgate\api\Item::TYPE_SHIPPING, 'SHIPPING', 'Shipping by UPS', 1, 599 );

// Create unique order id with corresponding database file.
$sOrderFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'cardgate_order_' . time();
if ( ! is_writable( dirname( $sOrderFile ) ) ) {
die( 'unable to create order file' );
}
$sOrderId = basename( $sOrderFile );

// Configure communication endpoint locations.
$sProtocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( 'off', $_SERVER['HTTPS'] ) !== 0 ? 'https' : 'http';
$sHostname = $_SERVER['HTTP_HOST'];
$sPath = dirname( isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'] );
$oTransaction->setCallbackUrl( "{$sProtocol}://{$sHostname}{$sPath}/4-callback.php" );
$oTransaction->setRedirectUrl( "{$sProtocol}://{$sHostname}{$sPath}/5-return.php" );

$oTransaction->setReference( $sOrderId );
$oTransaction->setDescription( 'test order ' . $sOrderId );

$oTransaction->register();

file_put_contents( $sOrderFile, json_encode( [
'status' => 'pending', // callback need to update this status
'transaction_id' => $oTransaction->getId()
] ) );

$sActionUrl = $oTransaction->getActionUrl();
if ( NULL !== $sActionUrl ) {
// Redirect the customer to the CardGate payment gateway.
header( 'Location: ' . $sActionUrl );
} else {
// Transaction was successfull without need for customer interaction.
echo 'OK';
}

} catch ( cardgate\api\Exception $oException_ ) {
echo htmlspecialchars( $oException_->getMessage() );
}
22 changes: 22 additions & 0 deletions examples/2-payment-ideal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
try {

include 'init.php';

$aIssuers = $oCardGate->methods()->get( cardgate\api\Method::IDEAL )->getIssuers();

echo '<form method="post" action="1-payment.php">';
echo '<input type="hidden" name="option" value="ideal">';
echo 'Select your bank: <select name="issuer">';

foreach( $aIssuers as $aIssuer ) {
echo '<option value="' . $aIssuer['id'] . '">' . $aIssuer['name'] . '</option>';
}

echo '<option value="">or select later</option></select>';
echo '<button>Submit</button>';
echo '</form>';

} catch ( cardgate\api\Exception $oException_ ) {
echo htmlspecialchars( $oException_->getMessage() );
}
21 changes: 21 additions & 0 deletions examples/3-methods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
try {

include 'init.php';

$aMethods = $oCardGate->methods()->all( $iSiteId );

echo '<form method="post" action="1-payment.php">';
echo 'Select payment option: <select name="option">';

foreach( $aMethods as $oMethod ) {
echo '<option value="' . $oMethod->getId() . '">' . $oMethod->getId() . '</option>';
}

echo '<option value="">or select later</option></select>';
echo '<button>Submit</button>';
echo '</form>';

} catch ( cardgate\api\Exception $oException_ ) {
echo htmlspecialchars( $oException_->getMessage() );
}
26 changes: 26 additions & 0 deletions examples/4-callback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
try {

include 'init.php';

// Make sure callback parameters are from the CardGate gateway.
if ( FALSE == $oCardGate->transactions()->verifyCallback( $_GET, $sSiteKey ) ) {
die( 'invalid callback' );
}

// Overwrite order database file with updated status.
$sOrderFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $_GET['reference'];
if ( ! file_exists( $sOrderFile ) ) {
die( 'invalid transaction' );
}
file_put_contents( $sOrderFile, json_encode( [
'status' => $_GET['status'],
'transaction_id' => $_GET['transaction']
] ) );

// The gateway expects a formatted response.
die( "{$_GET['transaction']}.{$_GET['code']}" );

} catch ( cardgate\api\Exception $oException_ ) {
echo htmlspecialchars( $oException_->getMessage() );
}
22 changes: 22 additions & 0 deletions examples/5-return.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
try {

include 'init.php';

// Retrieve status of transaction.
$sOrderFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $_GET['reference'];
if (
! file_exists( $sOrderFile )
|| FALSE == ( $sOrderData = file_get_contents( $sOrderFile ) )
|| FALSE == ( $aOrderData = json_decode( $sOrderData, TRUE ) )
|| ! isset( $aOrderData['status'] )
) {
die( 'invalid transaction' );
}

// Print status.
echo "transaction has status: <strong>{$aOrderData['status']}</strong><br><a href=\"1-payment.php\">new transaction</a>";

} catch ( cardgate\api\Exception $oException_ ) {
echo htmlspecialchars( $oException_->getMessage() );
}
26 changes: 26 additions & 0 deletions examples/6-refund.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
try {

include 'init.php';

$aDetails = [];
$oTransaction = $oCardGate->transactions()->get( 'T16A21948968', $aDetails );

if ( $oTransaction->canRefund() ) {
$oTransaction->refund( 50 );
echo '€ 0,50 of transaction ' . $oTransaction->getId() . ' refunded.';

$iRemainder_ = 0;
if (
$oTransaction->canRefund( $iRemainder_ )
&& $iRemainder_ > 0
) {
echo ' € ' . number_format( $iRemainder_ / 100, 2, ',', '.' ) . ' remaining.';
}
} else {
echo 'Transaction ' . $oTransaction->getId() . ' can not be refunded.';
}

} catch ( cardgate\api\Exception $oException_ ) {
echo htmlspecialchars( $oException_->getMessage() );
}
15 changes: 15 additions & 0 deletions examples/init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
require_once dirname( __FILE__ ) . '/../src/Autoloader.php';

cardgate\api\Autoloader::register();

$oCardGate = new cardgate\api\Client( 1, '<merchant key>', TRUE );
$oCardGate->setIp( $_SERVER['REMOTE_ADDR'] );
$oCardGate->setLanguage( 'nl' );
$oCardGate->version()->setPlatformName( 'PHP' );
$oCardGate->version()->setPlatformVersion( phpversion() );
$oCardGate->version()->setPluginName( 'Custom Implementation' );
$oCardGate->version()->setPluginVersion( '0.0.1' );

//$iSiteId = 44;
//$sSiteKey = '<optional site key>';

0 comments on commit 8f7395f

Please sign in to comment.