甜支付/甜支付-PHP

甜支付-PHP PHP 库

dev-master 2016-08-05 09:58 UTC

This package is not auto-updated.

Last update: 2024-09-15 00:33:42 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Composer

您可以通过 Composer 安装绑定。运行以下命令

composer require sweetpay/sweetpay-php dev-master

进入 sweetpay-php 目录并运行

composer install

这将创建 src 目录内的 vendor 目录。

要使用绑定,使用 Composer 的 自动加载

require_once('pathto/vendor/autoload.php');

还推荐使用 spl 自动加载器。

   /*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');

要求

PHP 5.4 及以上。

入门指南

使用终端为 src/logs 目录设置权限为 777

    sudo chmod 777 logs

在此文件中,所有调试信息将通过 monolog/monolog 添加。

设置条件

    
    // 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
    

运行交易

    $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);
    
        }

有关交易和订阅的具体示例,请参阅 Test/* 目录