<?php

class Stripe{
    public static $apiKey = null;
    public static $apiBase = 'https://api.stripe.com/v1/charges';
    public static $apiUploadBase = 'https://uploads.stripe.com';
    public static $apiVersion = null;
    public static $accountId = null;
    public static $verifySslCerts = true;
    public static $appInfo = null;
    public static $logger = null;
    const VERSION = '4.10.0';


	public static function getApiKey()
	{
		return self::$apiKey;
	}

	public static function setApiKey($apiKey)
	{
		self::$apiKey = $apiKey;
	}

	public static function getApiVersion()
	{
		return self::$apiVersion;
	}
	public static function setApiVersion($apiVersion)
	{
		self::$apiVersion = $apiVersion;
	}

	public static function getVerifySslCerts()
	{
		return self::$verifySslCerts;
	}
    /**
     * @param boolean $verify
     */
    public static function setVerifySslCerts($verify)
    {
    	self::$verifySslCerts = $verify;
    }

    public static function getAccountId()
    {
    	return self::$accountId;
    }

    public static function setAccountId($accountId)
    {
    	self::$accountId = $accountId;
    }


    public static function getAppInfo()
    {
    	return self::$appInfo;
    }

    public static function setAppInfo($appName, $appVersion = null, $appUrl = null)
    {
    	if (self::$appInfo === null) {
    		self::$appInfo = array();
    	}
    	self::$appInfo['name'] = $appName;
    	self::$appInfo['version'] = $appVersion;
    	self::$appInfo['url'] = $appUrl;
    }

    public static function Charge($amount,$token){
    	$ch = curl_init(self::$apiBase);
    	$data = [
    		'amount'=>100,
    		'currency'=>'usd',
    		'source' =>$token,
    		'metadata'=>array('order_id'=>'12345')
    	];
    	$username = self::$apiKey.":";
    	// $data = json_encode($data);
    	curl_setopt($ch,CURLOPT_HEADER,false);
    	curl_setopt($ch,CURLOPT_USERPWD,$username);
    	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    	curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); 
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    	$response = curl_exec($ch);
    	$response = json_decode($response);

    	if(isset($response->error)){
    		throw new Exception($response->error->message);
    	}
    	return $response;
    }

}
