Plugin Directory

Changeset 2034945


Ignore:
Timestamp:
02/20/2019 09:58:03 AM (7 years ago)
Author:
plenigo
Message:

Version 1.8.5

Location:
plenigo/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • plenigo/trunk/plenigo_sdk/plenigo/internal/ApiURLs.php

    r1999856 r2034945  
    3737
    3838    /**
     39     * This URL is used to add user access rights.
     40     */
     41    const PRODUCT_ACCESS_RIGHTS_ADDITION_WITH_DETAILS_URL = "/api/v2/access/{USER_ID}/addWithDetails";
     42
     43    /**
    3944     * This URL is used to remove user access rights.
    4045     */
     
    9398     * This URL is used to get all the products this user has bouight
    9499     */
    95     const USER_PRODUCTS = "/api/v2/user/{USER_ID}/products";
     100    const USER_PRODUCTS = "/api/v2/user/{USER_ID}/products";    /**
     101
     102     * This URL is used to get all the products this user has bouight with their details
     103     */
     104    const USER_PRODUCTS_DETAILS = "/api/v2/user/product/details";
    96105
    97106    /**
     
    236245    const CHECKOUT_PRODUCT = "/api/v2/checkout/free/product/{PROD_ID}/{USER_ID}";
    237246
     247
     248    /**
     249     * This URL is used to import users.
     250     */
     251    const USER_IMPORT_URL = "/api/v2/import/customers?useExternalCustomerId={USE_EXTERNAL_ID}";
     252
     253
    238254}
  • plenigo/trunk/plenigo_sdk/plenigo/internal/services/Service.php

    r1999856 r2034945  
    231231     * @return mixed The request response or null
    232232     *
    233      * @throws PlenigoException
     233     * @throws PlenigoException|RegistrationException
    234234     */
    235235    protected static function executeRequest($pRequest, $pErrorSource, $pErrorMsg) {
     
    240240            throw $exception;
    241241        }
    242         catch (Exception $exc) {
     242        catch (\Exception $exc) {
    243243            $errorCode = ErrorCode::getTranslation($pErrorSource, $exc->getCode());
    244244            if (empty($errorCode) || is_null($errorCode)) {
  • plenigo/trunk/plenigo_sdk/plenigo/internal/utils/EncryptionUtils.php

    r1704513 r2034945  
    3434
    3535    /**
     36     * @var string Encryption algorithm to use
     37     */
     38    private static $openSSLAlgorithm = 'AES-128-CTR';
     39
     40    /**
    3641     * Encryption encoding mode to use
    3742     */
     
    7378        $preparedKey = self::prepareKey($key);
    7479
    75         $encryptedData = mcrypt_encrypt(
    76             self::$cryptoAlgorithm, $preparedKey, $data, self::$cryptoEncoding, $ivKey
    77         );
     80        if (self::useOpenSSL()) {
     81            $encryptedData = self::openSSLEncrypt($data, $preparedKey, $ivKey);
     82        } else {
     83            $encryptedData = mcrypt_encrypt(
     84                self::$cryptoAlgorithm, $preparedKey, $data, self::$cryptoEncoding, $ivKey
     85            );
     86        }
    7887
    7988        return bin2hex($encryptedData . $ivKey);
     
    107116        $preparedKey = self::prepareKey($key);
    108117
     118        if (self::useOpenSSL()) {
     119            return self::openSSLDecrypt($encryptedData, $preparedKey, $ivKey);
     120        }
     121
    109122        return mcrypt_decrypt(
    110123            self::$cryptoAlgorithm, $preparedKey, $encryptedData, self::$cryptoEncoding, $ivKey
     
    113126
    114127    /**
     128     * @param string $encryptedData
     129     * @param string $key
     130     * @param string $iv
     131     * @return string
     132     */
     133    private static function openSSLDecrypt($encryptedData, $key, $iv) {
     134        return openssl_decrypt( $encryptedData, self::$openSSLAlgorithm, $key, OPENSSL_RAW_DATA, $iv);
     135    }
     136
     137    /**
     138     * @param string $data
     139     * @param string $key
     140     * @param string $iv
     141     * @return string
     142     */
     143    private static function openSSLEncrypt($data, $key, $iv) {
     144        return openssl_encrypt( $data, self::$openSSLAlgorithm, $key, OPENSSL_RAW_DATA, $iv);
     145    }
     146
     147    /**
    115148     * <p>
    116149     * Determines if an specific algorithm is available on the host.
     
    124157    private static function hasEncryptionAlgorithm($algorithmName, $libraryDir = null)
    125158    {
     159        // run with openSSL
     160        if (self::useOpenSSL()) {
     161            $algorithms = openssl_get_cipher_methods();
     162            return in_array(self::$openSSLAlgorithm, $algorithms);
     163        }
     164
    126165        $algorithms = mcrypt_list_algorithms($libraryDir);
    127166
    128167        return in_array($algorithmName, $algorithms);
     168    }
     169
     170    /**
     171     * should we use openSSL lib?
     172     *
     173     * @return bool
     174     */
     175    private static function useOpenSSL() {
     176        return (function_exists('openssl_encrypt') && function_exists('openssl_decrypt'));
    129177    }
    130178
     
    139187    private static function createIVKey()
    140188    {
     189
     190        //run with openSSL
     191        if (self::useOpenSSL()) {
     192            return openssl_random_pseudo_bytes(self::getIVSize());
     193        }
     194
    141195        $ivSize = self::getIVSize();
    142 
    143196        return mcrypt_create_iv($ivSize, MCRYPT_RAND);
    144197    }
     
    154207    private static function getIVSize()
    155208    {
     209        if (self::useOpenSSL()) {
     210            return openssl_cipher_iv_length(self::$openSSLAlgorithm);
     211        }
     212
    156213        return mcrypt_get_iv_size(self::$cryptoAlgorithm, self::$cryptoEncoding);
    157214    }
  • plenigo/trunk/plenigo_sdk/plenigo/services/AccessService.php

    r1999856 r2034945  
    8383    }
    8484
     85
     86    /**
     87     * Grant a user the right to access one or multiple products with details.
     88     * Use this method to add things like receipts to each access right.
     89     * @see https://api.plenigo.com/#!/access/addUserAccessDetail
     90     *
     91     * @param string $customerId The Customer ID
     92     * @param boolean $useExternalCustomerId flag indicating if customer id is an external customer id
     93     * @param string $startTime time when access should start in the format Y-m-d
     94     * @param string $endTime time when access should end in the format Y-m-d
     95     * @param array $accessRights ids of the products to grant customer access to
     96     *  $accessRights = [
     97     *      [
     98     *      'productId' => (string, optional): Product id to add access for. ,
     99     *      'receipt'   => (string, optional): Receipt of the user. ,
     100     *      'source'    => (string, optional): Access right source.
     101     *      ],
     102     * ]
     103     *
     104     * @throws PlenigoException
     105     */
     106    public static function grantUserAccessWithDetails($customerId, $useExternalCustomerId, $startTime, $endTime, $accessRights = [])
     107    {
     108        $testModeText = (PlenigoManager::get()->isTestMode()) ? 'true' : 'false';
     109
     110        foreach ($accessRights as $accessRight) {
     111            if (empty($accessRight['productId'])) {
     112                throw new PlenigoException("Parameter accessRights hast to be of array format with the following structure: [\n[\n'productId' => (string),\n'receipt' => (string, optional),\n'source' => (string, optional),\n],\n]");
     113            }
     114        }
     115
     116        $map = array(
     117            'useExternalCustomerId' => $useExternalCustomerId,
     118            ApiParams::TEST_MODE => $testModeText,
     119            'details' => $accessRights
     120        );
     121
     122        if(!empty($startTime)) {
     123            $map['startTime'] = date('Y-m-d', strtotime($startTime));
     124        }
     125
     126        if(!empty($endTime)) {
     127            $map['endTime'] = date('Y-m-d', strtotime($endTime));
     128        }
     129
     130        $url = str_ireplace(ApiParams::URL_USER_ID_TAG, $customerId, ApiURLs::PRODUCT_ACCESS_RIGHTS_ADDITION_WITH_DETAILS_URL);
     131
     132        $request = static::postJSONRequest($url, false, $map);
     133
     134        $appTokenRequest = new static($request);
     135
     136        parent::executeRequest($appTokenRequest, ApiURLs::PRODUCT_ACCESS_RIGHTS_ADDITION_WITH_DETAILS_URL, self::ERR_MSG_POST);
     137    }
     138
    85139    /**
    86140     * Removes a user's access right from one or multiple products.
  • plenigo/trunk/plenigo_sdk/plenigo/services/CheckoutService.php

    r1704513 r2034945  
    9797        return true;
    9898    }
     99
     100    /**
     101     * Purchase a complete order. Returns orderID of purchase
     102     *
     103     * @example external user, pay per invoice \plenigo\services\CheckoutService::purchase(4711, [['product_id' => 'P_amrSQ6154783308456', 'title' => 'some blue shoes', 'description' => 'Size 8, special design', 'amount' => 4]], 'INVOICE', true);
     104     * @example internal user (default), pay per prefered payment (default) \plenigo\services\CheckoutService::purchase('AIPM7JHMETZY', [['product_id' => 'P_amrSQ6154783308456', 'amount' => 1]], 'PREFFERED');
     105     *
     106     *
     107     * @see https://plenigo.github.io/api_purchase_php
     108     * @param string $customerId ID of plenigo-customer.
     109     * @param array $order
     110     * @param string $paymentMethod
     111     * @param bool $useMerchantCustomerId
     112     * @return string OrderID
     113     * @throws PlenigoException
     114     */
     115    public static function purchase($customerId, $order, $paymentMethod = 'PREFFERED', $useMerchantCustomerId = false) {
     116        // purchase(customer_id, [['product_id' => '1', 'title' => 'title', 'description' => '2', 'amount' => 1]], 'PREFFERED')
     117
     118        if (!isset($customerId)) {
     119            throw new PlenigoException("CustomerID is not optional");
     120        }
     121
     122        if (empty($order) || !is_array($order)) {
     123            throw new PlenigoException("Order is not optional and should be of type array");
     124        }
     125
     126        foreach ($order as $orderItem) {
     127            if (empty($orderItem['product_id'])) {
     128                throw new PlenigoException("Each orderItem needs the key product_id with a valid plenigo productID as value");
     129            }
     130        }
     131
     132        return  bin2hex(openssl_random_pseudo_bytes(15));
     133    }
    99134   
    100135    /**
  • plenigo/trunk/plenigo_sdk/plenigo/services/CompanyService.php

    r1999856 r2034945  
    9090            'endDate' => date("Y-m-d H:i",strtotime($endDate)),
    9191            'page' => SdkUtils::clampNumber($page, 0, null),
    92             'size' => SdkUtils::clampNumber($size, 10, 100)
     92            'size' => SdkUtils::clampNumber($size, 10, 250)
    9393        );
    9494
     
    124124            'testMode' => $testMode ? 'true' : 'false',
    125125            'page' => SdkUtils::clampNumber($page, 0, null),
    126             'size' => SdkUtils::clampNumber($size, 10, 100)
     126            'size' => SdkUtils::clampNumber($size, 10, 250)
    127127        );
    128128
     
    158158            'testMode' => $testMode ? 'true' : 'false',
    159159            'page' => SdkUtils::clampNumber($page, 0, null),
    160             'size' => SdkUtils::clampNumber($size, 10, 100)
     160            'size' => SdkUtils::clampNumber($size, 10, 250)
    161161        );
    162162
     
    242242        $map = array(
    243243            'page' => SdkUtils::clampNumber($page, 0, null),
    244             'size' => SdkUtils::clampNumber($size, 10, 100),
     244            'size' => SdkUtils::clampNumber($size, 10, 250),
    245245            'startDate' => $start,
    246246            'endDate' => $end
     
    320320        $map = array(
    321321            'page' => SdkUtils::clampNumber($page, 0, null),
    322             'size' => SdkUtils::clampNumber($size, 10, 100),
     322            'size' => SdkUtils::clampNumber($size, 10, 250),
    323323            'startDate' => $start,
    324324            'endDate' => $end,
     
    357357        $map = array(
    358358            'page' => SdkUtils::clampNumber($page, 0, null),
    359             'size' => SdkUtils::clampNumber($size, 10, 100),
     359            'size' => SdkUtils::clampNumber($size, 10, 250),
    360360            'startDate' => $start,
    361361            'endDate' => $end,
  • plenigo/trunk/plenigo_sdk/plenigo/services/UserService.php

    r1919357 r2034945  
    2121use plenigo\internal\ApiURLs;
    2222use plenigo\internal\Cache;
     23use plenigo\internal\exceptions\RegistrationException;
    2324use plenigo\internal\models\Customer;
    2425use plenigo\internal\services\Service;
     
    5556    const ERR_USER_LOGIN = "Error while verifying user";
    5657    const INF_MSG_ACCESS = "User tried to access an item!";
     58    const ERR_MSG_ACCESS = "User can't access item";
    5759
    5860    /**
     
    135137        try {
    136138            $result = parent::executeRequest($LoginRequest, ApiURLs::USER_LOGIN, self::ERR_USER_LOGIN);
    137             $cachedData = array(
    138                 'result' => $result,
    139                 'error'  => $error
    140             );
    141             Cache::set(md5($email.$password), $cachedData);
     139
    142140            return $result;
    143141        }
     
    500498    }
    501499
     500
     501    /**
     502     * Get AccessRights with their Details
     503     *
     504     * @see https://api.plenigo.com/#!/user/hasBoughtProductWithProducts
     505     *
     506     * @param $pCustomerId
     507     * @param array|string $productId
     508     * @param bool $useExternalCustomerId
     509     * @return \stdClass
     510     * @throws PlenigoException|RegistrationException|\Exception
     511     */
     512    public static function getProductsBoughtWithDetails($pCustomerId, $productId, $useExternalCustomerId = false)
     513    {
     514
     515        $productIds = is_array($productId) ? implode(",", $productId) : $productId;
     516
     517        $params = array(
     518            'customerId' => $pCustomerId,
     519            'productId' => $productIds,
     520            ApiParams::USE_EXTERNAL_CUSTOMER_ID => ($useExternalCustomerId ? 'true' : 'false')
     521        );
     522
     523        $url = ApiURLs::USER_PRODUCTS_DETAILS;
     524
     525        $request = static::getRequest($url, false, $params);
     526
     527        $appTokenRequest = new static($request);
     528
     529        try {
     530            $data = parent::executeRequest($appTokenRequest, $url, self::ERR_MSG_ACCESS);
     531            return $data;
     532        } catch (PlenigoException $exception) {
     533            // 403 is no access and should not result in an exception
     534            if (403 !== $exception->getCode()) {
     535                throw $exception;
     536            }
     537        }
     538
     539        $ret = new \stdClass();
     540        $ret->accessGranted = false;
     541        $ret->userProducts = array();
     542        return $ret;
     543    }
     544
    502545    /**
    503546     * Gets the user data using the current plenigo session cookie.
  • plenigo/trunk/plenigo_wordpress.php

    r2008626 r2034945  
    55  Plugin URI: http://wordpress.org/plugins/plenigo/
    66  Description: So far, the technical implementation of paid content has been time-consuming and costly for publishing houses and media companies. plenigo puts an end to this.
    7   Version: 1.8.4
     7  Version: 1.8.5
    88  Author: Plenigo
    99  Author URI: https://www.plenigo.com
     
    3030  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    3131 */
    32 define('PLENIGO_VERSION', '1.8.4');
     32define('PLENIGO_VERSION', '1.8.5');
    3333
    3434// Plenigo JavaScript SDK / Services
  • plenigo/trunk/readme.txt

    r2008626 r2034945  
    33Tags: paywall, e-commerce, Ecommerce, paid content software, subscriptions, newspaper, media, pay-per-read, pay, plugin, donate, money, transaction, bank, visa, mastercard, credit, debit, card, widget, give, pay what you want, plenigo, payment
    44Requires at least: 4.0.0
    5 Tested up to: 5.0.2
    6 Stable tag: 1.8.4
     5Tested up to: 5.0.3
     6Stable tag: 1.8.5
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.