sweetpay / sweetpay-php
sweetpay-php PHP Library
dev-master
2016-08-05 09:58 UTC
Requires
- php: >=5.4
- monolog/monolog: 1.*
Requires (Dev)
- phpmailer/phpmailer: ~5.2
This package is not auto-updated.
Last update: 2025-01-05 01:47:05 UTC
README
Composer
You can install the bindings via Composer. Run the following command:
composer require sweetpay/sweetpay-php dev-master
go to to the sweetpay-php directory and run:
composer install
this will create a vendor directory inside the src directory.
To use the bindings, use Composer's autoload:
require_once('pathto/vendor/autoload.php');
Also recommended it to use the spl autoloader.
/*Needed for loading the classes inside src*/ function autoload($className) { $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strrpos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require $fileName; } spl_autoload_register('autoload');
Requirements
PHP 5.4 and later.
Getting started
Set permission for src/logs directory as 777, using the terminal:
sudo chmod 777 logs
in this file all the debug information will be added using monolog/monolog.
Set up conditions
// The intital setup, some curl setup can be changed in this array $setup = array( "apiKey" => (string) "NNq7Rcnb8y8jGTsU", "stage" => (boolean) true, "DEFAULT_TIMEOUT" => (int ) 30 ); try { // run the setup \Sweetpay\CheckoutCond::setCondition($setup); } catch (Exception $e) { $input = array('line' => __LINE__, 'path' => __FILE__, 'input' => $setup); \Sweetpay\Helper::errorMessage($e, $input); // if any error, check stdout for any error message and logs/* var_dump(\Sweetpay\CheckoutCond::getApiKey()); } // end of try
Run a transaction
$transactionData = array( 'transactons' => array( array('amount' => '100', 'currency' => 'SEK') , array('amount' => '200', 'currency' => 'SEK') ), 'country' => 'SE', 'merchantId' => 'paylevo'); try { $Check = new \Sweetpay\CheckOut($transactionData); $vars = $Check->getOutput() ; // check the respons, var_dump($vars); } catch (Exception $e) { $input = array('line' => __LINE__, 'path' => __FILE__, 'input' => $transactionData); \Sweetpay\Helper::errorMessage($e, $input); }
For a concreate and working exempel for both transactions and subscription see Test/* directory