Changeset 2034945
- Timestamp:
- 02/20/2019 09:58:03 AM (7 years ago)
- Location:
- plenigo/trunk
- Files:
-
- 9 edited
-
plenigo_sdk/plenigo/internal/ApiURLs.php (modified) (3 diffs)
-
plenigo_sdk/plenigo/internal/services/Service.php (modified) (2 diffs)
-
plenigo_sdk/plenigo/internal/utils/EncryptionUtils.php (modified) (7 diffs)
-
plenigo_sdk/plenigo/services/AccessService.php (modified) (1 diff)
-
plenigo_sdk/plenigo/services/CheckoutService.php (modified) (1 diff)
-
plenigo_sdk/plenigo/services/CompanyService.php (modified) (6 diffs)
-
plenigo_sdk/plenigo/services/UserService.php (modified) (4 diffs)
-
plenigo_wordpress.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
plenigo/trunk/plenigo_sdk/plenigo/internal/ApiURLs.php
r1999856 r2034945 37 37 38 38 /** 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 /** 39 44 * This URL is used to remove user access rights. 40 45 */ … … 93 98 * This URL is used to get all the products this user has bouight 94 99 */ 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"; 96 105 97 106 /** … … 236 245 const CHECKOUT_PRODUCT = "/api/v2/checkout/free/product/{PROD_ID}/{USER_ID}"; 237 246 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 238 254 } -
plenigo/trunk/plenigo_sdk/plenigo/internal/services/Service.php
r1999856 r2034945 231 231 * @return mixed The request response or null 232 232 * 233 * @throws PlenigoException 233 * @throws PlenigoException|RegistrationException 234 234 */ 235 235 protected static function executeRequest($pRequest, $pErrorSource, $pErrorMsg) { … … 240 240 throw $exception; 241 241 } 242 catch ( Exception $exc) {242 catch (\Exception $exc) { 243 243 $errorCode = ErrorCode::getTranslation($pErrorSource, $exc->getCode()); 244 244 if (empty($errorCode) || is_null($errorCode)) { -
plenigo/trunk/plenigo_sdk/plenigo/internal/utils/EncryptionUtils.php
r1704513 r2034945 34 34 35 35 /** 36 * @var string Encryption algorithm to use 37 */ 38 private static $openSSLAlgorithm = 'AES-128-CTR'; 39 40 /** 36 41 * Encryption encoding mode to use 37 42 */ … … 73 78 $preparedKey = self::prepareKey($key); 74 79 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 } 78 87 79 88 return bin2hex($encryptedData . $ivKey); … … 107 116 $preparedKey = self::prepareKey($key); 108 117 118 if (self::useOpenSSL()) { 119 return self::openSSLDecrypt($encryptedData, $preparedKey, $ivKey); 120 } 121 109 122 return mcrypt_decrypt( 110 123 self::$cryptoAlgorithm, $preparedKey, $encryptedData, self::$cryptoEncoding, $ivKey … … 113 126 114 127 /** 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 /** 115 148 * <p> 116 149 * Determines if an specific algorithm is available on the host. … … 124 157 private static function hasEncryptionAlgorithm($algorithmName, $libraryDir = null) 125 158 { 159 // run with openSSL 160 if (self::useOpenSSL()) { 161 $algorithms = openssl_get_cipher_methods(); 162 return in_array(self::$openSSLAlgorithm, $algorithms); 163 } 164 126 165 $algorithms = mcrypt_list_algorithms($libraryDir); 127 166 128 167 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')); 129 177 } 130 178 … … 139 187 private static function createIVKey() 140 188 { 189 190 //run with openSSL 191 if (self::useOpenSSL()) { 192 return openssl_random_pseudo_bytes(self::getIVSize()); 193 } 194 141 195 $ivSize = self::getIVSize(); 142 143 196 return mcrypt_create_iv($ivSize, MCRYPT_RAND); 144 197 } … … 154 207 private static function getIVSize() 155 208 { 209 if (self::useOpenSSL()) { 210 return openssl_cipher_iv_length(self::$openSSLAlgorithm); 211 } 212 156 213 return mcrypt_get_iv_size(self::$cryptoAlgorithm, self::$cryptoEncoding); 157 214 } -
plenigo/trunk/plenigo_sdk/plenigo/services/AccessService.php
r1999856 r2034945 83 83 } 84 84 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 85 139 /** 86 140 * Removes a user's access right from one or multiple products. -
plenigo/trunk/plenigo_sdk/plenigo/services/CheckoutService.php
r1704513 r2034945 97 97 return true; 98 98 } 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 } 99 134 100 135 /** -
plenigo/trunk/plenigo_sdk/plenigo/services/CompanyService.php
r1999856 r2034945 90 90 'endDate' => date("Y-m-d H:i",strtotime($endDate)), 91 91 'page' => SdkUtils::clampNumber($page, 0, null), 92 'size' => SdkUtils::clampNumber($size, 10, 100)92 'size' => SdkUtils::clampNumber($size, 10, 250) 93 93 ); 94 94 … … 124 124 'testMode' => $testMode ? 'true' : 'false', 125 125 'page' => SdkUtils::clampNumber($page, 0, null), 126 'size' => SdkUtils::clampNumber($size, 10, 100)126 'size' => SdkUtils::clampNumber($size, 10, 250) 127 127 ); 128 128 … … 158 158 'testMode' => $testMode ? 'true' : 'false', 159 159 'page' => SdkUtils::clampNumber($page, 0, null), 160 'size' => SdkUtils::clampNumber($size, 10, 100)160 'size' => SdkUtils::clampNumber($size, 10, 250) 161 161 ); 162 162 … … 242 242 $map = array( 243 243 'page' => SdkUtils::clampNumber($page, 0, null), 244 'size' => SdkUtils::clampNumber($size, 10, 100),244 'size' => SdkUtils::clampNumber($size, 10, 250), 245 245 'startDate' => $start, 246 246 'endDate' => $end … … 320 320 $map = array( 321 321 'page' => SdkUtils::clampNumber($page, 0, null), 322 'size' => SdkUtils::clampNumber($size, 10, 100),322 'size' => SdkUtils::clampNumber($size, 10, 250), 323 323 'startDate' => $start, 324 324 'endDate' => $end, … … 357 357 $map = array( 358 358 'page' => SdkUtils::clampNumber($page, 0, null), 359 'size' => SdkUtils::clampNumber($size, 10, 100),359 'size' => SdkUtils::clampNumber($size, 10, 250), 360 360 'startDate' => $start, 361 361 'endDate' => $end, -
plenigo/trunk/plenigo_sdk/plenigo/services/UserService.php
r1919357 r2034945 21 21 use plenigo\internal\ApiURLs; 22 22 use plenigo\internal\Cache; 23 use plenigo\internal\exceptions\RegistrationException; 23 24 use plenigo\internal\models\Customer; 24 25 use plenigo\internal\services\Service; … … 55 56 const ERR_USER_LOGIN = "Error while verifying user"; 56 57 const INF_MSG_ACCESS = "User tried to access an item!"; 58 const ERR_MSG_ACCESS = "User can't access item"; 57 59 58 60 /** … … 135 137 try { 136 138 $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 142 140 return $result; 143 141 } … … 500 498 } 501 499 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 502 545 /** 503 546 * Gets the user data using the current plenigo session cookie. -
plenigo/trunk/plenigo_wordpress.php
r2008626 r2034945 5 5 Plugin URI: http://wordpress.org/plugins/plenigo/ 6 6 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. 47 Version: 1.8.5 8 8 Author: Plenigo 9 9 Author URI: https://www.plenigo.com … … 30 30 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 31 */ 32 define('PLENIGO_VERSION', '1.8. 4');32 define('PLENIGO_VERSION', '1.8.5'); 33 33 34 34 // Plenigo JavaScript SDK / Services -
plenigo/trunk/readme.txt
r2008626 r2034945 3 3 Tags: 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 4 4 Requires at least: 4.0.0 5 Tested up to: 5.0. 26 Stable tag: 1.8. 45 Tested up to: 5.0.3 6 Stable tag: 1.8.5 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.