Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed capture descriptor #4

Merged
merged 1 commit into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitattributes
Empty file.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.DS_Store
Binary file modified paylikepayment.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion paylikepayment/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Paylike prestashop
# Paylike prestashop
186 changes: 99 additions & 87 deletions paylikepayment/api/Adapter.php
Original file line number Diff line number Diff line change
@@ -1,87 +1,99 @@
<?php
namespace Paylike;
/**
* Class Adapter
* @package PaylikePayment\Api
* The adapter class taking care of the calls to the api.
*
* The purpose of this is to abstract the requests
* so that this can be changed depending on the environment.
*
* @version 1.0.0
*/
if ( ! class_exists( 'Paylike\\Adapter' ) ) {
class Adapter {

public $apiUrl = 'https://api.paylike.io';
private $apiKey;

/**
* Adapter constructor.
*
* @param $privateApiKey
*/
public function __construct( $privateApiKey ) {
if ( $privateApiKey ) {
$this->setApiKey( $privateApiKey );
} else {
// trigger_error( 'Private Key is missing!', E_USER_ERROR );
return null;
// return array('error' => 1, 'message' => "Private Key is missing!");

}
}

/**
* @param $key
* set the api key.
*/
public function setApiKey( $key ) {
$this->apiKey = $key;
}

/**
* @param $url this is required, do not use the full url,
* only prepend the params eg: transactions/' . $transactionId . '/captures'
* @param $data this is optional
* Actual call to the api via curl.
*
* @return bool|mixed
*/
public function request( $url, $data = null, $httpVerb = 'post' ) {
$url = $this->apiUrl . '/' . $url;
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json'
) );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_USERPWD, ":" . $this->apiKey );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
switch ( $httpVerb ) {
case 'post':
curl_setopt( $ch, CURLOPT_POST, true );
if ( $data ) {
$encoded = json_encode($data);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $encoded );
}
break;
case 'get':
// can add args here for future use
break;
}
$result = curl_exec( $ch );
$httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
curl_close( $ch );
$output = json_decode( $result, true );
if ( $httpCode >= 200 || $httpCode <= 299 ) {
return $output;
} else {
return false;
}
}

}
}
<?php
/**
*
* @author DerikonDevelopment <ionut@derikon.com>
* @copyright Copyright (c) permanent, DerikonDevelopment
* @license Addons PrestaShop license limitation
* @version 1.0.0
* @link http://www.derikon.com/
*
*/

namespace Paylike;

/**
* Class Adapter
* @package PaylikePayment\Api
* The adapter class taking care of the calls to the api.
*
* The purpose of this is to abstract the requests
* so that this can be changed depending on the environment.
*
* @version 1.0.0
*/
if (!class_exists('Paylike\\Adapter')) {
class Adapter
{
public $apiUrl = 'https://api.paylike.io';
private $apiKey;

/**
* Adapter constructor.
*
* @param $privateApiKey
*/
public function __construct($privateApiKey)
{
if ($privateApiKey) {
$this->setApiKey($privateApiKey);
} else {
// trigger_error( 'Private Key is missing!', E_USER_ERROR );
return null;
// return array('error' => 1, 'message' => "Private Key is missing!");
}
}

/**
* @param $key
* set the api key.
*/
public function setApiKey($key)
{
$this->apiKey = $key;
}

/**
* @param $url this is required, do not use the full url,
* only prepend the params eg: transactions/' . $transactionId . '/captures'
* @param $data this is optional
* Actual call to the api via curl.
*
* @return bool|mixed
*/
public function request($url, $data = null, $httpVerb = 'post')
{
$url = $this->apiUrl . '/' . $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json'
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERPWD, ":" . $this->apiKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
switch ($httpVerb) {
case 'post':
curl_setopt($ch, CURLOPT_POST, true);
if ($data) {
$encoded = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded);
}
break;
case 'get':
// can add args here for future use
break;
}
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$output = json_decode($result, true);
if ($httpCode >= 200 || $httpCode <= 299) {
return $output;
} else {
return false;
}
}
}
}
76 changes: 44 additions & 32 deletions paylikepayment/api/Card.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
<?php
namespace Paylike;
/**
* Class Card
* @package Paylike
* Handles card operations.
*
* @version 1.0.0
*/
if ( ! class_exists( 'Paylike\\Card' ) ) {
class Card {

/**
* Fetches information about a card
*
* @link https://github.com/paylike/api-docs#create-a-transaction
*
* @param $cardId
*
* @return int|mixed
*/
public static function fetch( $cardId ) {
$adapter = Client::getAdapter();
if ( ! $adapter ) {
// trigger_error( 'Adapter not set!', E_USER_ERROR );
return array('error' => 1, 'message' => "Adapter not set!");
}

return $adapter->request( 'cards/' . $cardId, $data = null, $httpVerb = 'get' );
}
}
}
<?php
/**
*
* @author DerikonDevelopment <ionut@derikon.com>
* @copyright Copyright (c) permanent, DerikonDevelopment
* @license Addons PrestaShop license limitation
* @version 1.0.0
* @link http://www.derikon.com/
*
*/

namespace Paylike;

/**
* Class Card
* @package Paylike
* Handles card operations.
*
* @version 1.0.0
*/
if (!class_exists('Paylike\\Card')) {
class Card
{
/**
* Fetches information about a card
*
* @link https://github.com/paylike/api-docs#create-a-transaction
*
* @param $cardId
*
* @return int|mixed
*/
public static function fetch($cardId)
{
$adapter = Client::getAdapter();
if (!$adapter) {
// trigger_error( 'Adapter not set!', E_USER_ERROR );
return array('error' => 1, 'message' => "Adapter not set!");
}

return $adapter->request('cards/' . $cardId, $data = null, $httpVerb = 'get');
}
}
}
115 changes: 64 additions & 51 deletions paylikepayment/api/Client.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,64 @@
<?php
namespace Paylike;
include_once( 'Adapter.php' );
include_once( 'Transaction.php' );
include_once( 'Card.php' );

/**
* Class Client
* @package Paylike
* Manages the app creation.
*/
if ( ! class_exists( 'Paylike\\Client' ) ) {
class Client {

/**
* @var
* This is the adapter, similar to a db engine,
* it can be changed with any class that has its capabilities,
* which are making requests to api. In the future the adapter
* will be extended from an interface.
*/
private static $adapter = null;

/**
* @param $privateApiKey
* Set the api key for future calls
*/
public static function setKey( $privateApiKey ) {
self::$adapter = new Adapter( $privateApiKey );
}

/**
* @param null $privateApiKey
* Returns the object that will be responsible for making the calls to the api
*
* @return bool|null|Adapter
*/
public static function getAdapter( $privateApiKey = null ) {
if ( self::$adapter ) {
return self::$adapter;
} else {
if ( $privateApiKey ) {
return new Adapter( $privateApiKey );
} else {
return false;
}
}
}

}
}
<?php
/**
*
* @author DerikonDevelopment <ionut@derikon.com>
* @copyright Copyright (c) permanent, DerikonDevelopment
* @license Addons PrestaShop license limitation
* @version 1.0.0
* @link http://www.derikon.com/
*
*/

namespace Paylike;

include_once('Adapter.php');
include_once('Transaction.php');
include_once('Card.php');

/**
* Class Client
* @package Paylike
* Manages the app creation.
*/
if (!class_exists('Paylike\\Client')) {
class Client
{

/**
* @var
* This is the adapter, similar to a db engine,
* it can be changed with any class that has its capabilities,
* which are making requests to api. In the future the adapter
* will be extended from an interface.
*/
private static $adapter = null;

/**
* @param $privateApiKey
* Set the api key for future calls
*/
public static function setKey($privateApiKey)
{
self::$adapter = new Adapter($privateApiKey);
}

/**
* @param null $privateApiKey
* Returns the object that will be responsible for making the calls to the api
*
* @return bool|null|Adapter
*/
public static function getAdapter($privateApiKey = null)
{
if (self::$adapter) {
return self::$adapter;
} else {
if ($privateApiKey) {
return new Adapter($privateApiKey);
} else {
return false;
}
}
}
}
}
Loading