BxPaymentModule.php 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Payment Payment
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_PAYMENT_ORDERS_TYPE_PENDING', 'pending');
  12. define('BX_PAYMENT_ORDERS_TYPE_PROCESSED', 'processed');
  13. define('BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION', 'subscription');
  14. define('BX_PAYMENT_ORDERS_TYPE_HISTORY', 'history');
  15. define('BX_PAYMENT_RESULT_SUCCESS', 0);
  16. /*
  17. * Subscriptions: statuses.
  18. */
  19. define('BX_PAYMENT_SBS_STATUS_SCHEDULED', 'scheduled');
  20. define('BX_PAYMENT_SBS_STATUS_TRIAL', 'trial');
  21. define('BX_PAYMENT_SBS_STATUS_ACTIVE', 'active');
  22. define('BX_PAYMENT_SBS_STATUS_UNPAID', 'unpaid');
  23. define('BX_PAYMENT_SBS_STATUS_PAUSED', 'paused');
  24. define('BX_PAYMENT_SBS_STATUS_CANCELED', 'canceled');
  25. define('BX_PAYMENT_SBS_STATUS_UNKNOWN', 'unknown');
  26. /*
  27. * Subscriptions: period units.
  28. */
  29. define('BX_PAYMENT_SBS_PU_YEAR', 'year');
  30. define('BX_PAYMENT_SBS_PU_MONTH', 'month');
  31. define('BX_PAYMENT_SBS_PU_WEEK', 'week');
  32. define('BX_PAYMENT_SBS_PU_DAY', 'day');
  33. define('BX_PAYMENT_SBS_PU_HOUR', 'hour');
  34. define('BX_PAYMENT_SBS_PU_MINUTE', 'minute');
  35. /*
  36. * Invoice: statuses.
  37. */
  38. define('BX_PAYMENT_INV_STATUS_UNPAID', 'unpaid');
  39. define('BX_PAYMENT_INV_STATUS_PAID', 'paid');
  40. define('BX_PAYMENT_INV_STATUS_OVERDUE', 'overdue');
  41. /**
  42. * Payment module by BoonEx
  43. *
  44. * This module is needed to work with payment providers and organize the process
  45. * of some item purchasing. Shopping Cart and Orders Manager are included.
  46. *
  47. * Integration notes:
  48. * To integrate your module with this one, you need:
  49. * 1. Get 'Add To Cart' button using serviceGetAddToCartLink service.
  50. * 2. Add info about your module in the 'bx_pmt_modules' table.
  51. * 3. Realize the following service methods in your Module class.
  52. * a. serviceGetItems($iSellerId) - Is used in Orders Administration to get all products of the requested seller(vendor).
  53. * b. serviceGetCartItem($iClientId, $iItemId) - Is used in Shopping Cart to get one product by specified id.
  54. * c. serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrderId) - Register purchased product.
  55. * d. serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrderId) - Unregister the product purchased earlier.
  56. * @see You may see an example of integration in Membership module.
  57. *
  58. *
  59. * Profile's Wall:
  60. * no spy events
  61. *
  62. *
  63. *
  64. * Spy:
  65. * no spy events
  66. *
  67. *
  68. *
  69. * Memberships/ACL:
  70. * Doesn't depend on user's membership.
  71. *
  72. *
  73. *
  74. * Service methods:
  75. *
  76. * Is used to get "Add to cart" link for some item(s) in your module.
  77. * @see BxPmtModule::serviceGetAddToCartLink
  78. * BxDolService::call('payment', 'get_add_to_cart_link', array($iSellerId, $mixedModuleId, $iItemId, $iItemCount));
  79. *
  80. * Check transaction(s) in database which satisty all conditions.
  81. * @see BxPmtModule::serviceGetOrdersInfo
  82. * BxDolService::call('payment', 'get_orders_info', array($aConditions), 'Orders');
  83. *
  84. * Get total count of items in Shopping Cart.
  85. * @see BxPmtModule::serviceGetCartItemsCount
  86. * BxDolService::call('payment', 'get_cart_items_count', array($iUserId, $iOldCount));
  87. * @note is needed for internal usage(integration with member tool bar).
  88. *
  89. * Get Shopping cart content.
  90. * @see BxPmtModule::serviceGetCartItems
  91. * BxDolService::call('payment', 'get_cart_items');
  92. * @note is needed for internal usage(integration with member tool bar).
  93. *
  94. *
  95. * Alerts:
  96. * no alerts available
  97. *
  98. */
  99. class BxPaymentModule extends BxBaseModPaymentModule
  100. {
  101. protected $_iUserId;
  102. protected $_aOrderTypes;
  103. function __construct($aModule)
  104. {
  105. parent::__construct($aModule);
  106. $this->_iUserId = $this->getProfileId();
  107. $this->_aOrderTypes = array(
  108. BX_PAYMENT_ORDERS_TYPE_PENDING,
  109. BX_PAYMENT_ORDERS_TYPE_PROCESSED,
  110. BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION,
  111. BX_PAYMENT_ORDERS_TYPE_HISTORY
  112. );
  113. }
  114. /**
  115. * Manage Orders Methods
  116. */
  117. public function actionGetClients()
  118. {
  119. $sTerm = bx_get('term');
  120. $aResult = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  121. echoJson($aResult);
  122. }
  123. public function actionGetItems($sType, $iModuleId)
  124. {
  125. $iSellerId = $this->getProfileId();
  126. $aItems = $this->callGetCartItems((int)$iModuleId, array($iSellerId));
  127. echoJson(array(
  128. 'code' => 0,
  129. 'eval' => $this->_oConfig->getJsObject('processed') . '.onSelectModule(oData);',
  130. 'data' => $this->_oTemplate->displayItems($sType, $aItems)
  131. ));
  132. }
  133. public function actionGetFilterValuesItem($iSellerId, $iModuleId)
  134. {
  135. $sItems = '<option value="">' . _t('_bx_payment_txt_all_items') . '</option>';
  136. if(empty($iSellerId) || empty($iModuleId))
  137. return echoJson(array('code' => 1, 'content' => $sItems));
  138. $aItems = $this->callGetCartItems((int)$iModuleId, array($iSellerId));
  139. $this->_oConfig->sortByColumn('title', $aItems);
  140. foreach($aItems as $aItem)
  141. $sItems .= '<option value="' . $aItem['id'] . '">' . $aItem['title'] . '</option>';
  142. echoJson(array('code' => 0, 'content' => $sItems));
  143. }
  144. public function serviceGetSafeServices()
  145. {
  146. $a = parent::serviceGetSafeServices();
  147. return array_merge($a, array (
  148. 'GetBlockJoin' => 'BxPaymentJoin',
  149. 'GetBlockCarts' => 'BxPaymentCart',
  150. 'GetBlockCart' => 'BxPaymentCart',
  151. 'GetBlockCartHistory' => 'BxPaymentCart',
  152. 'GetBlockListMy' => 'BxPaymentSubscriptions',
  153. 'GetBlockHistory' => 'BxPaymentSubscriptions',
  154. ));
  155. }
  156. /**
  157. * @page service Service Calls
  158. * @section bx_payment Payment
  159. * @subsection bx_payment-purchase_processing Purchase Processing
  160. * @subsubsection bx_payment-get_modules_with_payments get_modules_with_payments
  161. *
  162. * @code bx_srv('bx_payment', 'get_modules_with_payments', []); @endcode
  163. *
  164. * Get modules with payments functionality
  165. *
  166. * @return array with modules names
  167. *
  168. * @see BxPaymentModule::serviceGetModulesWithPayments
  169. */
  170. /**
  171. * @ref bx_payment-get_modules_with_payments "get_modules_with_payments"
  172. */
  173. public function serviceGetModulesWithPayments()
  174. {
  175. return $this->_oDb->getModulesWithPayments();
  176. }
  177. /**
  178. * @page service Service Calls
  179. * @section bx_payment Payment
  180. * @subsection bx_payment-purchase_processing Purchase Processing
  181. * @subsubsection bx_payment-is_credits_only is_credits_only
  182. *
  183. * @code bx_srv('bx_payment', 'is_credits_only'); @endcode
  184. *
  185. * Check whether the 'Credits Only' mode is enabled or not.
  186. *
  187. * @return boolean value determining the result of checking.
  188. *
  189. * @see BxPaymentModule::serviceIsCreditsOnly
  190. */
  191. /**
  192. * @ref bx_payment-is_credits_only "is_credits_only"
  193. */
  194. public function serviceIsCreditsOnly()
  195. {
  196. return $this->_oConfig->isCreditsOnly();
  197. }
  198. /**
  199. * @page service Service Calls
  200. * @section bx_payment Payment
  201. * @subsection bx_payment-purchase_processing Purchase Processing
  202. * @subsubsection bx_payment-is_accepting_payments is_accepting_payments
  203. *
  204. * @code bx_srv('bx_payment', 'is_accepting_payments', [...]); @endcode
  205. *
  206. * Check whether the specified vendor has a configured payment provider or not.
  207. *
  208. * @param $iVendorId integer value with vendor ID.
  209. * @param $sPaymentType (optional) string value with payment type. If specified then the vendor will be checked for having the payment provider of the requested type.
  210. * @return boolean value determining the result of checking.
  211. *
  212. * @see BxPaymentModule::serviceIsAcceptingPayments
  213. */
  214. /**
  215. * @ref bx_payment-is_accepting_payments "is_accepting_payments"
  216. */
  217. public function serviceIsAcceptingPayments($iVendorId, $sPaymentType = '')
  218. {
  219. $bResult = false;
  220. switch($sPaymentType) {
  221. case BX_PAYMENT_TYPE_SINGLE:
  222. $aProvidersCart = $this->_oDb->getVendorInfoProvidersSingle($iVendorId);
  223. $bResult = !empty($aProvidersCart);
  224. break;
  225. case BX_PAYMENT_TYPE_RECURRING:
  226. $aProvidersSubscription = $this->_oDb->getVendorInfoProvidersRecurring($iVendorId);
  227. $bResult = !empty($aProvidersSubscription);
  228. break;
  229. default:
  230. $aProviders = $this->_oDb->getVendorInfoProviders($iVendorId);
  231. $bResult = !empty($aProviders);
  232. }
  233. return $bResult;
  234. }
  235. /**
  236. * @deprecated since version 11.0.0
  237. *
  238. * @see BxPaymentModule::serviceIsProviderOptions
  239. */
  240. public function serviceIsPaymentProvider($iVendorId, $sVendorProvider, $sPaymentType = '')
  241. {
  242. return $this->serviceIsProviderOptions($iVendorId, $sVendorProvider, $sPaymentType);
  243. }
  244. /**
  245. * @deprecated since version 11.0.0
  246. *
  247. * @see BxPaymentModule::serviceGetProviderOptions
  248. */
  249. public function serviceGetPaymentProvider($iVendorId, $sVendorProvider, $sPaymentType = '')
  250. {
  251. return $this->serviceGetProviderOptions($iVendorId, $sVendorProvider, $sPaymentType);
  252. }
  253. /**
  254. * @page service Service Calls
  255. * @section bx_payment Payment
  256. * @subsection bx_payment-purchase_processing Purchase Processing
  257. * @subsubsection bx_payment-is_provider_options is_provider_options
  258. *
  259. * @code bx_srv('bx_payment', 'is_provider_options', [...]); @endcode
  260. *
  261. * Check whether the specified vendor has configured the specified payment provider or not.
  262. *
  263. * @param $iVendorId integer value with vendor ID.
  264. * @param $sVendorProvider string value with payment provider name.
  265. * @param $sPaymentType (optional) string value with payment type. If specified then the vendor will be checked for having the payment provider of the requested type.
  266. * @return boolean value determining the result of checking.
  267. *
  268. * @see BxPaymentModule::serviceIsProviderOptions
  269. */
  270. /**
  271. * @ref bx_payment-is_provider_options "is_provider_options"
  272. */
  273. public function serviceIsProviderOptions($iVendorId, $sVendorProvider, $sPaymentType = '')
  274. {
  275. $aProvider = $this->serviceGetProviderOptions($iVendorId, $sVendorProvider, $sPaymentType);
  276. return $aProvider !== false;
  277. }
  278. /**
  279. * @page service Service Calls
  280. * @section bx_payment Payment
  281. * @subsection bx_payment-purchase_processing Purchase Processing
  282. * @subsubsection bx_payment-get_provider_options get_provider_options
  283. *
  284. * @code bx_srv('bx_payment', 'get_provider_options', [...]); @endcode
  285. *
  286. * Get configuration settings for the payment provider entered by the specified vendor.
  287. *
  288. * @param $iVendorId integer value with vendor ID.
  289. * @param $sVendorProvider string value with payment provider name.
  290. * @param $sPaymentType (optional) string value with payment type. If specified then the vendor will be checked for having the payment provider of the requested type.
  291. * @return an array with special format describing the payment provider or false value if something is wrong.
  292. *
  293. * @see BxPaymentModule::serviceGetProviderOptions
  294. */
  295. /**
  296. * @ref bx_payment-get_provider_options "get_provider_options"
  297. */
  298. public function serviceGetProviderOptions($iVendorId, $sVendorProvider, $sPaymentType = '')
  299. {
  300. $aProviders = array();
  301. switch($sPaymentType) {
  302. case BX_PAYMENT_TYPE_SINGLE:
  303. $aProviders = $this->_oDb->getVendorInfoProvidersSingle($iVendorId);
  304. break;
  305. case BX_PAYMENT_TYPE_RECURRING:
  306. $aProviders = $this->_oDb->getVendorInfoProvidersRecurring($iVendorId);
  307. break;
  308. default:
  309. $aProviders = $this->_oDb->getVendorInfoProviders($iVendorId);
  310. }
  311. return !empty($aProviders) && !empty($aProviders[$sVendorProvider]) && is_array(($aProviders[$sVendorProvider])) ? $aProviders[$sVendorProvider] : false;
  312. }
  313. /**
  314. * @page service Service Calls
  315. * @section bx_payment Payment
  316. * @subsection bx_payment-other Other
  317. * @subsubsection bx_payment-get_options_default_currency_code get_options_default_currency_code
  318. *
  319. * @code bx_srv('bx_payment', 'get_options_default_currency_code', [...]); @endcode
  320. *
  321. * Get an array with available currencies. Is used in forms.
  322. *
  323. * @return an array with available currencies represented as key => value pairs.
  324. *
  325. * @see BxPaymentModule::serviceGetOptionsDefaultCurrencyCode
  326. */
  327. /**
  328. * @ref bx_payment-get_options_default_currency_code "get_options_default_currency_code"
  329. */
  330. public function serviceGetOptionsDefaultCurrencyCode()
  331. {
  332. $CNF = &$this->_oConfig->CNF;
  333. $aCurrencies = BxDolForm::getDataItems($CNF['OBJECT_FORM_PRELISTS_CURRENCIES']);
  334. $aResult = array();
  335. foreach($aCurrencies as $sKey => $sValue)
  336. $aResult[] = array(
  337. 'key' => $sKey,
  338. 'value' => $sValue
  339. );
  340. return $aResult;
  341. }
  342. /**
  343. * @page service Service Calls
  344. * @section bx_payment Payment
  345. * @subsection bx_payment-other Other
  346. * @subsubsection bx_payment-get_options_site_admin get_options_site_admin
  347. *
  348. * @code bx_srv('bx_payment', 'get_options_site_admin', [...]); @endcode
  349. *
  350. * Get an array with profiles which can be used as 'Site Admin (Owner)'. 'Site Admin' is a person who will be displayed to buyers when something is selling on behalf of the site.
  351. *
  352. * @return an array with profiles represented as key => value pairs.
  353. *
  354. * @see BxPaymentModule::serviceGetOptionsSiteAdmin
  355. */
  356. /**
  357. * @ref bx_payment-get_options_site_admin "get_options_site_admin"
  358. */
  359. public function serviceGetOptionsSiteAdmin()
  360. {
  361. $aResult = array(
  362. array('key' => '', 'value' => _t('_Select_one'))
  363. );
  364. $aIds = $this->_oDb->getAdminsIds();
  365. foreach($aIds as $iId) {
  366. $aUser = $this->getProfileInfo($iId);
  367. $aResult[] = array(
  368. 'key' => $iId,
  369. 'value' => $aUser['name']
  370. );
  371. }
  372. return $aResult;
  373. }
  374. public function serviceGetMenuAddonManageTools()
  375. {
  376. return array(
  377. 'counter1_value' => (int)$this->_oDb->getInvoices(array('type' => 'status', 'status' => BX_PAYMENT_INV_STATUS_PAID, 'count' => true)),
  378. 'counter1_caption' => _t('_bx_payment_menu_item_title_admt_addon_counter1_caption'),
  379. 'counter2_value' => (int)$this->_oDb->getInvoices(array('type' => 'status', 'status' => BX_PAYMENT_INV_STATUS_OVERDUE, 'count' => true)),
  380. 'counter2_caption' => _t('_bx_payment_menu_item_title_admt_addon_counter2_caption'),
  381. 'counter3_value' => (int)$this->_oDb->getInvoices(array('type' => 'all_count'))
  382. );
  383. }
  384. /**
  385. * Cart Processing Methods
  386. */
  387. public function actionAddToCart($iSellerId, $iModuleId, $iItemId, $iItemCount, $sCustom = '')
  388. {
  389. if(empty($sCustom) && bx_get('custom') !== false)
  390. $sCustom = bx_process_input(bx_get('custom'));
  391. $aCustom = array();
  392. if(!empty($sCustom)) {
  393. $aCustom = unserialize(base64_decode($sCustom));
  394. if(empty($aCustom) || !is_array($aCustom))
  395. $aCustom = array();
  396. }
  397. $aResult = $this->getObjectCart()->serviceAddToCart($iSellerId, $iModuleId, $iItemId, $iItemCount, $aCustom);
  398. echoJson($aResult);
  399. }
  400. /**
  401. * Isn't used yet.
  402. */
  403. public function actionDeleteFromCart($iSellerId, $iModuleId, $iItemId)
  404. {
  405. echoJson($this->getObjectCart()->serviceDeleteFromCart($iSellerId, $iModuleId, $iItemId));
  406. }
  407. /**
  408. * Isn't used yet.
  409. */
  410. public function actionEmptyCart($iSellerId)
  411. {
  412. echoJson($this->getObjectCart()->serviceDeleteFromCart($iSellerId));
  413. }
  414. public function actionSubscribe()
  415. {
  416. $iSellerId = bx_process_input(bx_get('seller_id'), BX_DATA_INT);
  417. $sSellerProvider = bx_process_input(bx_get('seller_provider'));
  418. $iModuleId = bx_process_input(bx_get('module_id'), BX_DATA_INT);
  419. $iItemId = bx_process_input(bx_get('item_id'), BX_DATA_INT);
  420. $iItemCount = bx_process_input(bx_get('item_count'), BX_DATA_INT);
  421. if(empty($iItemCount))
  422. $iItemCount = 1;
  423. $sRedirect = bx_process_input(bx_get('redirect'));
  424. $sCustom = bx_process_input(bx_get('custom'));
  425. $aCustom = array();
  426. if(!empty($sCustom)) {
  427. $aCustom = unserialize(base64_decode($sCustom));
  428. if(empty($aCustom) || !is_array($aCustom))
  429. $aCustom = array();
  430. }
  431. $aResult = $this->getObjectSubscriptions()->serviceSubscribe($iSellerId, $sSellerProvider, $iModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
  432. $bRedirect = !empty($aResult['redirect']);
  433. if(!empty($aResult['popup'])) {
  434. $sContent = '';
  435. $sContent .= $this->_oTemplate->displayCartJs(BX_PAYMENT_TYPE_RECURRING, $iSellerId);
  436. $sContent .= !empty($aResult['popup']['html']) ? $aResult['popup']['html'] : $aResult['popup'];
  437. return $this->_oTemplate->displayPageCodeResponse($sContent, false, true);
  438. }
  439. if(!empty($aResult['code']))
  440. return $this->_oTemplate->displayPageCodeError($aResult['message']);
  441. if(!empty($aResult['message']) && !$bRedirect)
  442. return $this->_oTemplate->displayPageCodeResponse($aResult['message']);
  443. if($bRedirect) {
  444. header('Location: ' . $aResult['redirect']);
  445. exit;
  446. }
  447. }
  448. public function actionSubscribeJson()
  449. {
  450. $iSellerId = bx_process_input(bx_get('seller_id'), BX_DATA_INT);
  451. $sSellerProvider = bx_process_input(bx_get('seller_provider'));
  452. $iModuleId = bx_process_input(bx_get('module_id'), BX_DATA_INT);
  453. $iItemId = bx_process_input(bx_get('item_id'), BX_DATA_INT);
  454. $iItemCount = bx_process_input(bx_get('item_count'), BX_DATA_INT);
  455. if(empty($iItemCount))
  456. $iItemCount = 1;
  457. $sItemAddons = '';
  458. if(bx_get('item_addons') !== false) {
  459. $sItemAddons = bx_process_input(bx_get('item_addons'));
  460. if(is_array($sItemAddons))
  461. $sItemAddons = $this->_oConfig->a2s($sItemAddons);
  462. }
  463. $sRedirect = bx_process_input(bx_get('redirect'));
  464. $sCustom = bx_process_input(bx_get('custom'));
  465. $aCustom = array();
  466. if(!empty($sCustom)) {
  467. $aCustom = unserialize(base64_decode($sCustom));
  468. if(empty($aCustom) || !is_array($aCustom))
  469. $aCustom = array();
  470. }
  471. echoJson($this->getObjectSubscriptions()->serviceSubscribeWithAddons($iSellerId, $sSellerProvider, $iModuleId, $iItemId, $iItemCount, $sItemAddons, $sRedirect, $aCustom));
  472. }
  473. public function actionSubscriptionGetDetails($iId)
  474. {
  475. echoJson($this->_oTemplate->displaySubscriptionGetDetails($iId));
  476. }
  477. public function actionSubscriptionChangeDetails($iId)
  478. {
  479. echoJson($this->_oTemplate->displaySubscriptionChangeDetails($iId));
  480. }
  481. public function actionSubscriptionGetBilling($iId)
  482. {
  483. echoJson($this->_oTemplate->displaySubscriptionGetBilling($iId));
  484. }
  485. public function actionSubscriptionChangeBilling($iId)
  486. {
  487. echoJson($this->_oTemplate->displaySubscriptionChangeBilling($iId));
  488. }
  489. public function actionSubscriptionCancelation($iId)
  490. {
  491. $aResult = array('code' => 1, 'message' => _t('_bx_payment_err_cannot_perform'));
  492. $aPending = $this->_oDb->getOrderPending(array('type' => 'id', 'id' => $iId));
  493. if(empty($aPending) || !is_array($aPending))
  494. return echoJson($aResult);
  495. $aSubscription = $this->_oDb->getSubscription(array('type' => 'pending_id', 'pending_id' => $iId));
  496. if(empty($aSubscription) || !is_array($aSubscription))
  497. return echoJson($aResult);
  498. $oRecipient = BxDolProfile::getInstance((int)$aPending['seller_id']);
  499. if(!$oRecipient)
  500. return echoJson($aResult);
  501. $mixedResult = $this->isAllowedManage($aPending);
  502. if($mixedResult !== true)
  503. return echoJson(array('code' => 2, 'message' => $mixedResult));
  504. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($this->_oConfig->getPrefix('general') . 'cancelation_request', array(
  505. 'sibscription_id' => $aSubscription['subscription_id'],
  506. 'sibscription_customer' => $aSubscription['customer_id'],
  507. 'sibscription_date' => bx_time_js($aSubscription['date'], BX_FORMAT_DATE, true)
  508. ), 0, (int)$aPending['client_id']);
  509. $sEmail = '';
  510. $oProvider = $this->getObjectProvider($aPending['provider'], $aPending['seller_id']);
  511. if($oProvider !== false && $oProvider->isActive())
  512. $sEmail = $oProvider->getOption('cancellation_email');
  513. if(empty($sEmail))
  514. $sEmail = $oRecipient->getAccountObject()->getEmail();
  515. if(!sendMail($sEmail, $aTemplate['Subject'], $aTemplate['Body'], 0, array(), BX_EMAIL_SYSTEM))
  516. return echoJson($aResult);
  517. echoJson(array('code' => 0, 'message' => _t('_bx_payment_msg_cancelation_request_sent')));
  518. }
  519. public function actionSubscriptionCancel($iId, $mixedGridObject = false)
  520. {
  521. $aResult = array('code' => 1, 'message' => _t('_bx_payment_err_cannot_perform'));
  522. $aPending = $this->_oDb->getOrderPending(array('type' => 'id', 'id' => $iId));
  523. if(empty($aPending) || !is_array($aPending))
  524. return echoJson($aResult);
  525. $mixedResult = $this->isAllowedManage($aPending);
  526. if($mixedResult !== true)
  527. return echoJson(array('code' => 2, 'message' => $mixedResult));
  528. if(!$this->getObjectSubscriptions()->cancel($iId))
  529. return echoJson($aResult);
  530. if(empty($mixedGridObject) && bx_get('grid') !== false)
  531. $mixedGridObject = bx_process_input(bx_get('grid'));
  532. if(!empty($mixedGridObject) && $aPending['client_id'] == $this->getProfileId()) {
  533. $oGrid = BxDolGrid::getObjectInstance($mixedGridObject, $this->_oTemplate);
  534. $oGrid->addQueryParam('client_id', $aPending['client_id']);
  535. return echoJson(array('object' => $mixedGridObject, 'grid' => $oGrid->getCode(false), 'blink' => array($iId)));
  536. }
  537. else
  538. return echoJson(array('code' => 0, 'message' => _t('_bx_payment_msg_successfully_performed')));
  539. }
  540. /**
  541. * Payment Processing Methods
  542. */
  543. public function actionInitializeCheckout($sType)
  544. {
  545. if(!$this->isLogged())
  546. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_required_login');
  547. if(bx_get('seller_id') !== false && bx_get('provider') !== false && bx_get('items') !== false) {
  548. $iSellerId = bx_process_input(bx_get('seller_id'), BX_DATA_INT);
  549. $sProvider = bx_process_input(bx_get('provider'));
  550. $aItems = bx_process_input(bx_get('items'));
  551. $mixedResult = $this->serviceInitializeCheckout(BX_PAYMENT_TYPE_SINGLE, $iSellerId, $sProvider, $aItems);
  552. if($mixedResult !== true)
  553. return $this->_oTemplate->displayPageCodeError($mixedResult);
  554. }
  555. header('Location: ' . $this->_oConfig->getUrl('URL_CART'));
  556. exit;
  557. }
  558. /**
  559. * @page service Service Calls
  560. * @section bx_payment Payment
  561. * @subsection bx_payment-purchase_processing Purchase Processing
  562. * @subsubsection bx_payment-initialize_checkout initialize_checkout
  563. *
  564. * @code bx_srv('bx_payment', 'initialize_checkout', [...]); @endcode
  565. *
  566. * Initialize the checkout process.
  567. *
  568. * @param $sType string value with payment type (single or recurring).
  569. * @param $iSellerId integer value with seller ID.
  570. * @param $sProvider string value with payment provider name.
  571. * @param $aItems (optional) an array with items to be purchased.
  572. * @param $sRedirect (optional) string value with redirect URL if it's needed.
  573. * @param $aCustom (optional) array with custom data to attach to a payment.
  574. * @return the result depends on the payment provider which is used for processing or represented as string value with error message if something is wrong.
  575. *
  576. * @see BxPaymentModule::serviceInitializeCheckout
  577. */
  578. /**
  579. * @ref bx_payment-initialize_checkout "initialize_checkout"
  580. */
  581. public function serviceInitializeCheckout($sType, $iSellerId, $sProvider, $aItems = array(), $sRedirect = '', $aCustoms = array())
  582. {
  583. $bTypeSingle = $sType == BX_PAYMENT_TYPE_SINGLE;
  584. $bTypeRecurring = $sType == BX_PAYMENT_TYPE_RECURRING;
  585. if(!is_array($aItems))
  586. $aItems = array($aItems);
  587. $iSellerId = (int)$iSellerId;
  588. if($iSellerId == BX_PAYMENT_EMPTY_ID)
  589. return $this->_sLangsPrefix . 'err_unknown_vendor';
  590. $oProvider = $this->getObjectProvider($sProvider, $iSellerId);
  591. if($oProvider === false || !$oProvider->isActive())
  592. return $this->_sLangsPrefix . 'err_incorrect_provider';
  593. $aInfo = $this->getObjectCart()->getInfo($sType, $this->_iUserId, $iSellerId, $aItems);
  594. if(empty($aInfo) || $aInfo['vendor_id'] == BX_PAYMENT_EMPTY_ID || empty($aInfo['items']))
  595. return $this->_sLangsPrefix . 'err_empty_order';
  596. /*
  597. * Process FREE (price = 0) items for LOGGED IN members
  598. * WITHOUT processing via payment provider.
  599. * Note. This section isn't used for now!
  600. */
  601. $bProcessedFree = false;
  602. $sKeyPriceSingle = $this->_oConfig->getKey('KEY_ARRAY_PRICE_SINGLE');
  603. $sKeyPriceRecurring = $this->_oConfig->getKey('KEY_ARRAY_PRICE_RECURRING');
  604. foreach($aInfo['items'] as $iIndex => $aItem) {
  605. if((int)$aInfo['client_id'] == 0)
  606. continue;
  607. //--- For Single time payments.
  608. if($bTypeSingle && (float)$aItem[$sKeyPriceSingle] == 0) {
  609. $aCart = $this->_oDb->getCartContent($aInfo['client_id']);
  610. $aCartCustoms = !empty($aCart['customs']) ? unserialize($aCart['customs']) : array();
  611. $aCartItem = array($aInfo['vendor_id'], $aItem['module_id'], $aItem['id'], $aItem['quantity']);
  612. $aCartItemCustom = $this->_oConfig->pullCustom($aCartItem, $aCartCustoms);
  613. $aItemInfo = $this->callRegisterCartItem((int)$aItem['module_id'], array($aInfo['client_id'], $aInfo['vendor_id'], $aItem['id'], $aItem['quantity'], $this->_oConfig->getLicense(), $aCartItemCustom));
  614. if(!empty($aItemInfo) && is_array($aItemInfo)) {
  615. if(!empty($aItemInfo['addons']) && is_array($aItemInfo['addons']))
  616. foreach($aItemInfo['addons'] as $sAddon => $aAddon)
  617. $this->callRegisterCartItem((int)$aAddon['module_id'], array($aInfo['client_id'], $aInfo['vendor_id'], $aAddon['id'], $aAddon['quantity'], $this->_oConfig->getLicense(), $aCartItemCustom));
  618. $bProcessedFree = true;
  619. }
  620. $aInfo['items_count'] -= 1;
  621. unset($aInfo['items'][$iIndex]);
  622. $aCart['items'] = trim(preg_replace("'" . $this->_oConfig->descriptorA2S($aCartItem) . ":?'", "", $aCart['items']), ":");
  623. $this->_oDb->setCartItems($aInfo['client_id'], $aCart['items'], $aCartCustoms);
  624. }
  625. //--- For Recurring payments.
  626. if($bTypeRecurring && (float)$aItem[$sKeyPriceRecurring] == 0) {
  627. //TODO: Process FREE subscription here, if such situation will be possible.
  628. }
  629. }
  630. if(empty($aInfo['items']))
  631. return $this->_sLangsPrefix . ($bProcessedFree ? 'msg_successfully_processed_free' : 'err_empty_order');
  632. if($bTypeSingle && (empty($aCustoms) || !is_array($aCustoms))) {
  633. $aCart = $this->_oDb->getCartContent($aInfo['client_id']);
  634. $aCartCustoms = !empty($aCart['customs']) ? unserialize($aCart['customs']) : array();
  635. $aCustoms = array();
  636. foreach($aInfo['items'] as $aItem) {
  637. $sCartItem = $this->_oConfig->descriptorA2S(array($aItem['author_id'], $aItem['module_id'], $aItem['id']));
  638. $aCartItemCustom = $this->_oConfig->getCustom($sCartItem, $aCartCustoms);
  639. $this->_oConfig->putCustom($sCartItem, $aCartItemCustom, $aCustoms);
  640. }
  641. }
  642. bx_alert($this->getName(), 'before_pending', 0, bx_get_logged_profile_id(), array(
  643. 'client_id' => $this->_iUserId,
  644. 'type' => &$sType,
  645. 'provider' => &$sProvider,
  646. 'cart_info' => &$aInfo,
  647. 'custom' => &$aCustoms,
  648. ));
  649. $iPendingId = $this->_oDb->insertOrderPending($this->_iUserId, $sType, $sProvider, $aInfo, $aCustoms);
  650. if(empty($iPendingId))
  651. return $this->_sLangsPrefix . 'err_access_db';
  652. /*
  653. * Perform Join WITHOUT processing via payment provider
  654. * if a client ISN'T logged in and has only ONE FREE item in the card.
  655. * Note. This section isn't used for now because only a member can purchase!
  656. */
  657. if((int)$aInfo['client_id'] == 0 && (int)$aInfo['items_count'] == 1) {
  658. reset($aInfo['items']);
  659. $aItem = current($aInfo['items']);
  660. if(!empty($aItem) && $this->_oConfig->getPrice($sType, $aItem)) {
  661. $this->_oDb->updateOrderPending($iPendingId, array(
  662. 'order' => $this->_oConfig->getLicense(),
  663. 'error_code' => '1',
  664. 'error_msg' => ''
  665. ));
  666. $this->getObjectJoin()->performJoin($iPendingId);
  667. }
  668. }
  669. return $oProvider->initializeCheckout($iPendingId, $aInfo, $sRedirect);
  670. }
  671. public function actionFinalizeCheckout($sProvider, $mixedVendorId = "")
  672. {
  673. $aData = &$_REQUEST;
  674. $oProvider = $this->getObjectProvider($sProvider, $mixedVendorId);
  675. if($oProvider === false || !$oProvider->isActive())
  676. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_incorrect_provider');
  677. $aResult = $oProvider->finalizeCheckout($aData);
  678. if((int)$aResult['code'] != BX_PAYMENT_RESULT_SUCCESS)
  679. return $this->_oTemplate->displayPageCodeError($aResult['message']);
  680. $aPending = $this->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$aResult['pending_id']));
  681. $bTypeRecurring = $aPending['type'] == BX_PAYMENT_TYPE_RECURRING;
  682. if($bTypeRecurring) {
  683. $sStatus = BX_PAYMENT_SBS_STATUS_UNPAID;
  684. if(isset($aResult['paid']) && $aResult['paid'])
  685. $sStatus = BX_PAYMENT_SBS_STATUS_ACTIVE;
  686. else if(isset($aResult['trial']) && $aResult['trial'])
  687. $sStatus = BX_PAYMENT_SBS_STATUS_TRIAL;
  688. $aSubscription = array(
  689. 'customer_id' => $aResult['customer_id'],
  690. 'subscription_id' => $aResult['subscription_id'],
  691. 'status' => $sStatus
  692. );
  693. if(!$this->getObjectSubscriptions()->register($aPending, $aSubscription))
  694. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_already_registered');
  695. }
  696. $this->onPaymentRegisterBefore($aPending);
  697. //--- Check "Pay Before Join" situation
  698. if((int)$aPending['client_id'] == 0)
  699. $this->getObjectJoin()->performJoin((int)$aPending['id'], isset($aResult['client_name']) ? $aResult['client_name'] : '', isset($aResult['client_email']) ? $aResult['client_email'] : '');
  700. //--- Register payment for purchased items in associated modules
  701. if(!empty($aResult['paid']) || ($bTypeRecurring && !empty($aResult['trial'])))
  702. $this->registerPayment($aPending);
  703. bx_alert($this->getName(), 'finalize_checkout', 0, bx_get_logged_profile_id(), array(
  704. 'pending' => $aPending,
  705. 'transactions' => $this->_oDb->getOrderProcessed(array('type' => 'pending_id', 'pending_id' => (int)$aPending['id'])),
  706. 'provider' => $oProvider,
  707. 'message' => &$aResult['message'],
  708. 'result' => &$aResult,
  709. ));
  710. if($oProvider->needRedirect()) {
  711. header('Location: ' . $oProvider->getReturnUrl());
  712. exit;
  713. }
  714. if(!empty($aResult['redirect'])) {
  715. header('Location: ' . base64_decode(urldecode($aResult['redirect'])));
  716. exit;
  717. }
  718. $this->_oTemplate->displayPageCodeResponse($aResult['message']);
  719. }
  720. public function actionFinalizedCheckout($sProvider, $mixedVendorId = "")
  721. {
  722. $oProvider = $this->getObjectProvider($sProvider, $mixedVendorId);
  723. if($oProvider === false || !$oProvider->isActive())
  724. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_incorrect_provider');
  725. $aResult = $oProvider->finalizedCheckout();
  726. $this->_oTemplate->displayPageCodeResponse($aResult['message']);
  727. }
  728. public function actionNotify($sProvider, $mixedVendorId = "")
  729. {
  730. $oProvider = $this->getObjectProvider($sProvider, $mixedVendorId);
  731. if($oProvider === false || !$oProvider->isActive())
  732. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_incorrect_provider');
  733. $oProvider->notify();
  734. }
  735. /**
  736. * The method is needed to pass direct action calls to necessary Payment Provider.
  737. */
  738. public function actionCall($sProvider, $sAction, $mixedVendorId = BX_PAYMENT_EMPTY_ID)
  739. {
  740. $oProvider = $this->getObjectProvider($sProvider, $mixedVendorId);
  741. if($oProvider === false)
  742. BxDolRequest::methodNotFound($sAction, $this->getName());
  743. $sMethod = 'action' . bx_gen_method_name($sAction);
  744. if(!method_exists($oProvider, $sMethod))
  745. BxDolRequest::methodNotFound($sAction, $this->getName());
  746. return call_user_func_array(array($oProvider, $sMethod), array_slice(func_get_args(), 2));
  747. }
  748. public function onProfileJoin($iProfileId)
  749. {
  750. $this->getObjectJoin()->onProfileJoin($iProfileId);
  751. }
  752. public function onProfileDelete($iProfileId)
  753. {
  754. $this->_oDb->onProfileDelete($iProfileId);
  755. }
  756. public function isAllowedPurchase($aItem, $bPerform = false)
  757. {
  758. $iUserId = (int)$this->getProfileId();
  759. $aItemInfo = $this->callGetCartItem((int)$aItem['module_id'], array($aItem['item_id'], isset($aItem['custom']) ? $aItem['custom'] : array()));
  760. if(empty($aItemInfo))
  761. return false;
  762. if(isAdmin())
  763. return true;
  764. $aCheckResult = checkActionModule($iUserId, 'purchase', $this->getName(), $bPerform);
  765. if($aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)
  766. return true;
  767. return $aCheckResult[CHECK_ACTION_MESSAGE];
  768. }
  769. public function isAllowedSell($aItem, $bPerform = false)
  770. {
  771. $iUserId = (int)$this->getProfileId();
  772. if(!$iUserId)
  773. return false;
  774. $aItemInfo = $this->callGetCartItem((int)$aItem['module_id'], array($aItem['item_id']));
  775. if(empty($aItemInfo))
  776. return false;
  777. if(isAdmin())
  778. return true;
  779. $aCheckResult = checkActionModule($iUserId, 'sell', $this->getName(), $bPerform);
  780. if((int)$aItemInfo['author_id'] == $iUserId && $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)
  781. return true;
  782. return $aCheckResult[CHECK_ACTION_MESSAGE];
  783. }
  784. public function isAllowedManage($aPending, $bPerform = false)
  785. {
  786. $iUserId = (int)$this->getProfileId();
  787. if($iUserId == $aPending['client_id'] || $iUserId == $aPending['seller_id'] || isAdmin())
  788. return true;
  789. $aCheckResult = checkActionModule($iUserId, 'manage any purchase', $this->getName(), $bPerform);
  790. if($aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)
  791. return true;
  792. return $aCheckResult[CHECK_ACTION_MESSAGE];
  793. }
  794. public function isAllowedManageInvoices($bPerform = false)
  795. {
  796. if(BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR)) || isAdmin())
  797. return true;
  798. return _t('_sys_txt_access_denied');
  799. }
  800. public function checkData($iClientId, $iSellerId, $iModuleId, $iItemId, $iItemCount, $aCustom = array())
  801. {
  802. $CNF = &$this->_oConfig->CNF;
  803. if($iSellerId == BX_PAYMENT_EMPTY_ID || empty($iModuleId) || empty($iItemId) || empty($iItemCount))
  804. return array('code' => 1, 'message' => _t($CNF['T']['ERR_WRONG_DATA']));
  805. $iClientId = $this->getProfileId();
  806. if(empty($iClientId)) {
  807. $sLoginUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=login');
  808. return array('code' => 2, 'eval' => 'window.open("' . $sLoginUrl . '", "_self");');
  809. }
  810. $mixedResult = $this->isAllowedPurchase(array('module_id' => $iModuleId, 'item_id' => $iItemId, 'custom' => $aCustom));
  811. if($mixedResult !== true) {
  812. if(is_string($mixedResult) && !empty($mixedResult))
  813. return array('code' => 2, 'message' => $mixedResult);
  814. else
  815. return array('code' => 1, 'message' => _t($CNF['T']['ERR_WRONG_DATA']));
  816. }
  817. if($iClientId == $iSellerId)
  818. return array('code' => 3, 'message' => _t($CNF['T']['ERR_SELF_PURCHASE']));
  819. $aSeller = $this->getVendorInfo($iSellerId);
  820. if(!$aSeller['active'])
  821. return array('code' => 4, 'message' => _t($CNF['T']['ERR_INACTIVE_VENDOR']));
  822. return true;
  823. }
  824. public function registerPayment($mixedPending)
  825. {
  826. $aPending = is_array($mixedPending) ? $mixedPending : $this->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$mixedPending));
  827. if(empty($aPending) || !is_array($aPending))
  828. return false;
  829. $sType = $aPending['type'];
  830. $bTypeSingle = $sType == BX_PAYMENT_TYPE_SINGLE;
  831. if($bTypeSingle && (int)$aPending['processed'] == 1)
  832. return true;
  833. $iClientId = (int)$aPending['client_id'];
  834. $sLicense = $this->_oConfig->getLicense();
  835. $aCustoms = !empty($aPending['customs']) ? unserialize($aPending['customs']) : array();
  836. $aCart = array();
  837. if($bTypeSingle) {
  838. $aCart = $this->_oDb->getCartContent($iClientId);
  839. $aCart['customs'] = !empty($aCart['customs']) ? unserialize($aCart['customs']) : array();
  840. }
  841. $bResult = false;
  842. $aItems = $this->_oConfig->descriptorsM2A($aPending['items']);
  843. foreach($aItems as $aItem) {
  844. $sItem = $this->_oConfig->descriptorA2S(array($aItem['vendor_id'], $aItem['module_id'], $aItem['item_id']));
  845. $aItemCustom = $this->_oConfig->getCustom($sItem, $aCustoms);
  846. $sMethod = $bTypeSingle ? 'callRegisterCartItem' : 'callRegisterSubscriptionItem';
  847. $aItemInfo = $this->$sMethod((int)$aItem['module_id'], array($aPending['client_id'], $aPending['seller_id'], $aItem['item_id'], $aItem['item_count'], $aPending['order'], $sLicense, $aItemCustom));
  848. if(empty($aItemInfo) || !is_array($aItemInfo))
  849. continue;
  850. $this->_oDb->insertOrderProcessed(array(
  851. 'pending_id' => $aPending['id'],
  852. 'client_id' => $aPending['client_id'],
  853. 'seller_id' => $aPending['seller_id'],
  854. 'author_id' => $aItem['vendor_id'],
  855. 'module_id' => (int)$aItem['module_id'],
  856. 'item_id' => (int)$aItem['item_id'],
  857. 'item_count' => (int)$aItem['item_count'],
  858. 'amount' => (int)$aItem['item_count'] * $this->_oConfig->getPrice($sType, $aItemInfo),
  859. 'license' => $sLicense,
  860. ));
  861. if($bTypeSingle) {
  862. $this->_oConfig->pullCustom($sItem, $aCart['customs']);
  863. $aCart['items'] = trim(preg_replace("'" . $this->_oConfig->descriptorA2S($aItem) . ":?'", "", $aCart['items']), ":");
  864. }
  865. $bResult = true;
  866. }
  867. if($bTypeSingle)
  868. $this->_oDb->setCartItems($iClientId, $aCart['items'], $aCart['customs']);
  869. if($bResult) {
  870. $this->_oDb->updateOrderPending($aPending['id'], array('processed' => 1));
  871. $this->onPaymentRegister($aPending);
  872. }
  873. return $bResult;
  874. }
  875. public function refundPayment($mixedPending)
  876. {
  877. $aPending = is_array($mixedPending) ? $mixedPending : $this->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$mixedPending));
  878. if(empty($aPending) || !is_array($aPending))
  879. return false;
  880. $bTypeSingle = $aPending['type'] == BX_PAYMENT_TYPE_SINGLE;
  881. $iCanceled = 0;
  882. $aOrders = $this->_oDb->getOrderProcessed(array('type' => 'pending_id', 'pending_id' => (int)$aPending['id']));
  883. foreach($aOrders as $aOrder) {
  884. $sMethod = $bTypeSingle ? 'callUnregisterCartItem' : 'callUnregisterSubscriptionItem';
  885. $bResult = $this->$sMethod((int)$aOrder['module_id'], array($aOrder['client_id'], $aOrder['seller_id'], $aOrder['item_id'], $aOrder['item_count'], $aPending['order'], $aOrder['license']));
  886. if(!$bResult)
  887. continue;
  888. if($this->_oDb->deleteOrderProcessed($aOrder['id']))
  889. $iCanceled++;
  890. }
  891. if($iCanceled != count($aOrders))
  892. return false;
  893. $bResult = $this->_oDb->deleteOrderPending($aPending['id']);
  894. if($bResult)
  895. $this->onPaymentRefund($aPending);
  896. return $bResult;
  897. }
  898. /**
  899. * @deprecated since version 12.0.0
  900. *
  901. * @use BxPaymentSubscriptions::register instead.
  902. */
  903. public function registerSubscription($aPending, $aParams = array())
  904. {
  905. return $this->getObjectSubscriptions()->register($aPending, $aParams);
  906. }
  907. /**
  908. * @deprecated since version 12.0.0
  909. *
  910. * @use BxPaymentSubscriptions::cancelLocal instead.
  911. */
  912. public function cancelSubscription($mixedPending)
  913. {
  914. return $this->getObjectSubscriptions()->cancelLocal($mixedPending);
  915. }
  916. public function processCommissions()
  917. {
  918. if(!defined('BX_DOL_CRON_EXECUTE'))
  919. return;
  920. $CNF = &$this->_oConfig->CNF;
  921. if((int)date('j') == $CNF['PARAM_CMSN_INVOICE_ISSUE_DAY'])
  922. $this->_invoicesIssue();
  923. $this->_invoicesCheck();
  924. }
  925. protected function _invoicesIssue()
  926. {
  927. $CNF = &$this->_oConfig->CNF;
  928. $sInvoiceNameMask = 'INV-%d-%d-%d';
  929. $iMonth = date('m');
  930. $iYear = date('Y');
  931. $iPeriodStart = mktime(0, 0, 0, $iMonth-1, 1, $iYear);
  932. $iPeriodEnd = mktime(23, 59, 59, $iMonth, 0, $iYear);
  933. $iDateIssue = time();
  934. $iDateDue = $iDateIssue + 86400 * $CNF['PARAM_CMSN_INVOICE_LIFETIME'];
  935. $aCommissionsInfo = array();
  936. $aAclLevels = BxDolAcl::getInstance()->getMemberships(false, true, false, true);
  937. foreach($aAclLevels as $iAclLevelId => $sAclLevelTitle)
  938. $aCommissionsInfo[$iAclLevelId] = $this->_oDb->getCommissions(array('type' => 'acl_id', 'acl_id' => $iAclLevelId));
  939. $iMainSellerId = $this->_oConfig->getSiteAdmin();
  940. $aVendors = $this->_oDb->getOrderProcessed(array('type' => 'income', 'period_start' => $iPeriodStart, 'period_end' => $iPeriodEnd));
  941. foreach($aVendors as $aVendor) {
  942. $iVendorId = (int)$aVendor['id'];
  943. if($iVendorId == $iMainSellerId)
  944. continue;
  945. $aInvoice = $this->_oDb->getInvoices(array('type' => 'committent_id', 'committent_id' => $iVendorId, 'period_start' => $iPeriodStart, 'period_end' => $iPeriodEnd));
  946. if(!empty($aInvoice) && is_array($aInvoice))
  947. continue;
  948. $aVendorAcl = BxDolAcl::getInstance()->getMemberMembershipInfo($iVendorId);
  949. $aCommissions = $aCommissionsInfo[$aVendorAcl['id']];
  950. $fCommission = 0;
  951. foreach($aCommissions as $aCommission) {
  952. if((float)$aCommission['percentage'] > 0)
  953. $fCommission += (float)$aVendor['amount'] * (float)$aCommission['percentage'] / 100;
  954. if((float)$aCommission['installment'] > 0)
  955. $fCommission += (float)$aCommission['installment'];
  956. }
  957. $this->_oDb->insertInvoice(array(
  958. 'name' => sprintf($sInvoiceNameMask, $iMainSellerId, $iVendorId, $this->_oDb->getInvoices(array(
  959. 'type' => 'index',
  960. 'commissionaire_id' => $iMainSellerId,
  961. 'committent_id' => $iVendorId
  962. ))),
  963. 'commissionaire_id' => $iMainSellerId,
  964. 'committent_id' => $iVendorId,
  965. 'amount' => $fCommission,
  966. 'period_start' => $iPeriodStart,
  967. 'period_end' => $iPeriodEnd,
  968. 'date_issue' => $iDateIssue,
  969. 'date_due' => $iDateDue,
  970. 'status' => BX_PAYMENT_INV_STATUS_UNPAID
  971. ));
  972. }
  973. }
  974. protected function _invoicesCheck()
  975. {
  976. $CNF = &$this->_oConfig->CNF;
  977. $sPrefix = $this->_oConfig->getPrefix('general');
  978. $oEmailTemplates = BxDolEmailTemplates::getInstance();
  979. //--- Process expiring invoices.
  980. $aInvoices = $this->_oDb->getInvoices(array('type' => 'expiring'));
  981. if(!empty($aInvoices) && is_array($aInvoices))
  982. foreach($aInvoices as $aInvoice) {
  983. if((int)$aInvoice['ntf_exp'] > 0)
  984. continue;
  985. $oCommittent = BxDolProfile::getInstance($aInvoice['committent_id']);
  986. if(!$oCommittent)
  987. continue;
  988. $bResult = sendMailTemplate($sPrefix . 'expiring_notification_committent', 0, (int)$aInvoice['committent_id'], array(
  989. 'invoice' => $aInvoice['name'],
  990. 'days' => $CNF['PARAM_CMSN_INVOICE_EXPIRATION_NOTIFY'],
  991. 'period_start' => $this->_oConfig->formatDate($aInvoice['period_start']),
  992. 'period_end' => $this->_oConfig->formatDate($aInvoice['period_end']),
  993. 'date_issue' => $this->_oConfig->formatDateTime($aInvoice['date_issue']),
  994. 'date_due' => $this->_oConfig->formatDateTime($aInvoice['date_due']),
  995. ), BX_EMAIL_NOTIFY, true);
  996. if($bResult)
  997. $this->_oDb->updateInvoice($aInvoice['id'], array('ntf_exp' => 1));
  998. }
  999. //--- Process overdue invoices.
  1000. $aInvoices = $this->_oDb->getInvoices(array('type' => 'overdue'));
  1001. if(!empty($aInvoices) && is_array($aInvoices))
  1002. foreach($aInvoices as $aInvoice) {
  1003. if((int)$aInvoice['ntf_due'] > 0 && $aInvoice['status'] == BX_PAYMENT_INV_STATUS_OVERDUE)
  1004. continue;
  1005. $oCommittent = BxDolProfile::getInstance($aInvoice['committent_id']);
  1006. if(!$oCommittent)
  1007. continue;
  1008. $bResult = sendMailTemplate($sPrefix . 'overdue_notification_committent', 0, (int)$aInvoice['committent_id'], array(
  1009. 'invoice' => $aInvoice['name'],
  1010. 'period_start' => $this->_oConfig->formatDate($aInvoice['period_start']),
  1011. 'period_end' => $this->_oConfig->formatDate($aInvoice['period_end']),
  1012. 'date_issue' => $this->_oConfig->formatDateTime($aInvoice['date_issue']),
  1013. 'date_due' => $this->_oConfig->formatDateTime($aInvoice['date_due']),
  1014. ), BX_EMAIL_NOTIFY, true);
  1015. $this->_oDb->updateInvoice($aInvoice['id'], array(
  1016. 'status' => BX_PAYMENT_INV_STATUS_OVERDUE,
  1017. 'ntf_due' => $bResult ? 1 : 0
  1018. ));
  1019. }
  1020. }
  1021. public function processTimeTracker()
  1022. {
  1023. if(!defined('BX_DOL_CRON_EXECUTE'))
  1024. return;
  1025. $aSubscriptions = $this->_oDb->getSubscription(array(
  1026. 'type' => 'time_tracker',
  1027. 'status_active' => BX_PAYMENT_SBS_STATUS_ACTIVE,
  1028. 'status_trial' => BX_PAYMENT_SBS_STATUS_TRIAL,
  1029. 'status_unpaid' => BX_PAYMENT_SBS_STATUS_UNPAID,
  1030. 'pay_attempts_max' => $this->_oConfig->getPayAttemptsMax(),
  1031. 'pay_attempts_interval' => $this->_oConfig->getPayAttemptsInterval()
  1032. ));
  1033. if(empty($aSubscriptions) || !is_array($aSubscriptions))
  1034. return;
  1035. foreach($aSubscriptions as $aSubscription) {
  1036. $aPending = $this->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$aSubscription['pending_id']));
  1037. if(empty($aPending) || !is_array($aPending) || $aPending['type'] != BX_PAYMENT_TYPE_RECURRING) {
  1038. $this->log($aSubscription, 'Time Tracker', 'Cannot process subscription.');
  1039. continue;
  1040. }
  1041. $oProvider = $this->getObjectProvider($aPending['provider'], $aPending['seller_id']);
  1042. if($oProvider === false || !$oProvider->isActive() || !method_exists($oProvider, 'makePayment')) {
  1043. $this->log($aSubscription, 'Time Tracker', 'Payment provider unavailable or incorrect.');
  1044. continue;
  1045. }
  1046. if(!$oProvider->makePayment($aPending)) {
  1047. $this->log($aSubscription, 'Time Tracker', 'Payment cannot be processed.');
  1048. continue;
  1049. }
  1050. if(!$this->getObjectSubscriptions()->prolong($aPending)) {
  1051. $this->log($aSubscription, 'Time Tracker', 'Cannot prolong subscription.');
  1052. continue;
  1053. }
  1054. if(!$this->registerPayment($aPending)) {
  1055. $this->log($aSubscription, 'Time Tracker', 'Cannot register payment.');
  1056. continue;
  1057. }
  1058. }
  1059. }
  1060. public function onPaymentRegisterBefore($aPending, $aResult = array())
  1061. {
  1062. bx_alert('system', 'before_register_payment', 0, $aPending['client_id'], array('pending' => $aPending));
  1063. }
  1064. public function onPaymentRegister($aPending, $aResult = array())
  1065. {
  1066. $bTypeSingle = $aPending['type'] == BX_PAYMENT_TYPE_SINGLE;
  1067. if($bTypeSingle) {
  1068. $aItems = $this->_oConfig->descriptorsM2A($aPending['items']);
  1069. foreach($aItems as $aItem)
  1070. $this->isAllowedPurchase(array('module_id' => $aItem['module_id'], 'item_id' => $aItem['item_id']), true);
  1071. }
  1072. bx_alert('system', 'register_payment', 0, $aPending['client_id'], array('pending' => $aPending));
  1073. }
  1074. public function onPaymentRefund($aPending, $aResult = array())
  1075. {
  1076. bx_alert('system', 'refund_payment', 0, $aPending['client_id'], array('pending' => $aPending));
  1077. }
  1078. public function onSubscriptionCreate($aPending, $aSubscription, $aResult = array())
  1079. {
  1080. $aItems = $this->_oConfig->descriptorsM2A($aPending['items']);
  1081. $this->isAllowedPurchase(array('module_id' => $aItems[0]['module_id'], 'item_id' => $aItems[0]['item_id']), true);
  1082. bx_alert('system', 'create_subscription', 0, $aPending['client_id'], array(
  1083. 'pending' => $aPending,
  1084. 'subscription' => $aSubscription
  1085. ));
  1086. }
  1087. public function onSubscriptionProlong($aPending, $aSubscription, $aResult = array())
  1088. {
  1089. bx_alert('system', 'prolong_subscription', 0, $aPending['client_id'], array(
  1090. 'pending' => $aPending,
  1091. 'subscription' => $aSubscription
  1092. ));
  1093. }
  1094. public function onSubscriptionOverdue($aPending, $aSubscription, $aResult = array())
  1095. {
  1096. bx_alert('system', 'overdue_subscription', 0, $aPending['client_id'], array(
  1097. 'pending' => $aPending,
  1098. 'subscription' => $aSubscription
  1099. ));
  1100. }
  1101. public function onSubscriptionCancel($aPending, $aSubscription, $aResult = array())
  1102. {
  1103. bx_alert('system', 'cancel_subscription', 0, $aPending['client_id'], array(
  1104. 'pending' => $aPending,
  1105. 'subscription' => $aSubscription
  1106. ));
  1107. }
  1108. public function setSiteSubmenu($sSubmenu, $sSelModule, $sSelName)
  1109. {
  1110. $oSiteSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  1111. if(!$oSiteSubmenu)
  1112. return;
  1113. $sModuleSubmenu = $this->_oConfig->getObject($sSubmenu);
  1114. $oModuleSubmenu = BxDolMenu::getObjectInstance($sModuleSubmenu);
  1115. if(!$oModuleSubmenu)
  1116. return;
  1117. $oSiteSubmenu->setObjectSubmenu($sModuleSubmenu);
  1118. $oModuleSubmenu->setSelected($sSelModule, $sSelName);
  1119. }
  1120. public function getProviderButtonJs($aCartItem, $aProvider, $sRedirect = '', $aCustom = array())
  1121. {
  1122. $aButtonJs = array();
  1123. $iClientId = $this->getProfileId();
  1124. $sItemAddons = '';
  1125. if(count($aCartItem) == 5)
  1126. $sItemAddons = array_pop($aCartItem);
  1127. list($iSellerId, $iModuleId, $iItemId, $iItemCount) = $aCartItem;
  1128. $oProvider = $this->getObjectProvider($aProvider['name'], $iSellerId);
  1129. if($oProvider !== false && method_exists($oProvider, 'getButtonRecurring')) {
  1130. $aParams = array(
  1131. 'sObjNameCart' => $this->_oConfig->getJsObject('cart'),
  1132. 'iSellerId' => $iSellerId,
  1133. 'iModuleId' => $iModuleId,
  1134. 'iItemId' => $iItemId,
  1135. 'iItemCount' => $iItemCount,
  1136. 'sItemAddons' => $sItemAddons,
  1137. 'sRedirect' => $sRedirect,
  1138. 'sCustom' => base64_encode(serialize($aCustom))
  1139. );
  1140. $aCartInfo = $this->getObjectCart()->getInfo(BX_PAYMENT_TYPE_RECURRING, $iClientId, $iSellerId, $this->_oConfig->descriptorA2S($aCartItem));
  1141. if(!empty($aCartInfo['items_price']) && !empty($aCartInfo['items']) && is_array($aCartInfo['items'])) {
  1142. $aItem = array_shift($aCartInfo['items']);
  1143. $aParams = array_merge($aParams, array(
  1144. 'iAmount' => (int)round(100 * (float)$aCartInfo['items_price']),
  1145. 'sItemName' => $aItem['name'],
  1146. 'sItemTitle' => $aItem['title']
  1147. ));
  1148. }
  1149. $aButtonJs = $oProvider->getButtonRecurringJs($iClientId, $iSellerId, $aParams);
  1150. }
  1151. if(empty($aButtonJs) || !is_array($aButtonJs))
  1152. $aButtonJs = $this->getObjectSubscriptions()->serviceGetSubscribeJs($iSellerId, $aProvider['name'], $iModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
  1153. return $aButtonJs;
  1154. }
  1155. /**
  1156. * Integration with itslef which is needed to pay an invoice.
  1157. */
  1158. /**
  1159. * @page service Service Calls
  1160. * @section bx_payment Payment
  1161. * @subsection bx_payment-payments Payments
  1162. * @subsubsection bx_payment-get_payment_data get_payment_data
  1163. *
  1164. * @code bx_srv('bx_payment', 'get_payment_data', [...]); @endcode
  1165. *
  1166. * Get an array with module's description. Is needed for payments processing module.
  1167. *
  1168. * @return an array with module's description.
  1169. *
  1170. * @see BxPaymentModule::serviceGetPaymentData
  1171. */
  1172. /**
  1173. * @ref bx_payment-get_payment_data "get_payment_data"
  1174. */
  1175. public function serviceGetPaymentData()
  1176. {
  1177. return $this->_aModule;
  1178. }
  1179. /**
  1180. * @page service Service Calls
  1181. * @section bx_payment Payment
  1182. * @subsection bx_payment-payments Payments
  1183. * @subsubsection bx_payment-get_cart_item get_cart_item
  1184. *
  1185. * @code bx_srv('bx_payment', 'get_cart_item', [...]); @endcode
  1186. *
  1187. * Get an array with prodict's description. Is used in Shopping Cart in payments processing module.
  1188. *
  1189. * @param $mixedItemId product's ID or Unique Name.
  1190. * @return an array with prodict's description. Empty array is returned if something is wrong.
  1191. *
  1192. * @see BxPaymentModule::serviceGetCartItem
  1193. */
  1194. /**
  1195. * @ref bx_payment-get_cart_item "get_cart_item"
  1196. */
  1197. public function serviceGetCartItem($mixedItemId)
  1198. {
  1199. $CNF = &$this->_oConfig->CNF;
  1200. if(!$mixedItemId)
  1201. return array();
  1202. if(is_numeric($mixedItemId))
  1203. $aItem = $this->_oDb->getInvoices(array('type' => 'id', 'id' => (int)$mixedItemId));
  1204. else
  1205. $aItem = $this->_oDb->getInvoices(array('type' => 'name', 'name' => $mixedItemId));
  1206. if(empty($aItem) || !is_array($aItem))
  1207. return array();
  1208. $oCommissionaire = BxDolProfile::getInstanceMagic($aItem['commissionaire_id']);
  1209. return array (
  1210. 'id' => $aItem['id'],
  1211. 'author_id' => $aItem['commissionaire_id'],
  1212. 'name' => $aItem['name'],
  1213. 'title' => _t('_bx_payment_txt_invoice_title', $aItem['name'], $oCommissionaire->getDisplayName()),
  1214. 'description' => _t('_bx_payment_txt_invoice_description', bx_process_output($aItem['period_start'], BX_DATA_DATE_TS_UTC), bx_process_output($aItem['period_end'], BX_DATA_DATE_TS_UTC)),
  1215. 'url' => '',
  1216. 'price_single' => $aItem['amount'],
  1217. 'price_recurring' => '',
  1218. 'period_recurring' => 0,
  1219. 'period_unit_recurring' => '',
  1220. 'trial_recurring' => ''
  1221. );
  1222. }
  1223. /**
  1224. * @page service Service Calls
  1225. * @section bx_payment Payment
  1226. * @subsection bx_payment-payments Payments
  1227. * @subsubsection bx_payment-get_cart_items get_cart_items
  1228. *
  1229. * @code bx_srv('bx_payment', 'get_cart_items', [...]); @endcode
  1230. *
  1231. * Get an array with prodicts' descriptions by seller. Is used in Manual Order Processing in payments processing module.
  1232. *
  1233. * @param $iCommissionaireId commissionaire ID.
  1234. * @return an array with prodicts' descriptions. Empty array is returned if something is wrong or seller doesn't have any products.
  1235. *
  1236. * @see BxPaymentModule::serviceGetCartItems
  1237. */
  1238. /**
  1239. * @ref bx_payment-get_cart_items "get_cart_items"
  1240. */
  1241. public function serviceGetCartItems($iCommissionaireId)
  1242. {
  1243. $CNF = &$this->_oConfig->CNF;
  1244. $iCommissionaireId = (int)$iCommissionaireId;
  1245. if(empty($iCommissionaireId))
  1246. return array();
  1247. $sCommissionaireName = BxDolProfile::getInstanceMagic($iCommissionaireId)->getDisplayName();
  1248. $aItems = $this->_oDb->getInvoices(array('type' => 'commissionaire_id', 'commissionaire_id' => $iCommissionaireId));
  1249. $aResult = array();
  1250. foreach($aItems as $aItem)
  1251. $aResult[] = array(
  1252. 'id' => $aItem['id'],
  1253. 'author_id' => $aItem['commissionaire_id'],
  1254. 'name' => $aItem['name'],
  1255. 'title' => _t('_bx_payment_txt_invoice_title', $aItem['name'], $sCommissionaireName),
  1256. 'description' => _t('_bx_payment_txt_invoice_description', bx_process_output($aItem['period_start'], BX_DATA_DATE_TS_UTC), bx_process_output($aItem['period_end'], BX_DATA_DATE_TS_UTC)),
  1257. 'url' => '',
  1258. 'price_single' => $aItem['amount'],
  1259. 'price_recurring' => '',
  1260. 'period_recurring' => 0,
  1261. 'period_unit_recurring' => '',
  1262. 'trial_recurring' => ''
  1263. );
  1264. return $aResult;
  1265. }
  1266. /**
  1267. * @page service Service Calls
  1268. * @section bx_payment Payment
  1269. * @subsection bx_payment-payments Payments
  1270. * @subsubsection bx_payment-register_cart_item register_cart_item
  1271. *
  1272. * @code bx_srv('bx_payment', 'register_cart_item', [...]); @endcode
  1273. *
  1274. * Register a processed single time payment inside the Payment module. Is called with payment processing module after the payment was registered there.
  1275. *
  1276. * @param $iClientId client ID.
  1277. * @param $iSellerId seller ID
  1278. * @param $iItemId item ID.
  1279. * @param $iItemCount the number of purchased items.
  1280. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  1281. * @param $sLicense license number genereted with payment processing module for internal usage
  1282. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  1283. *
  1284. * @see BxPaymentModule::serviceRegisterCartItem
  1285. */
  1286. /**
  1287. * @ref bx_payment-register_cart_item "register_cart_item"
  1288. */
  1289. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  1290. {
  1291. $CNF = &$this->_oConfig->CNF;
  1292. $aItem = $this->serviceGetCartItem($iItemId);
  1293. if(empty($aItem) || !is_array($aItem))
  1294. return array();
  1295. if(!$this->_oDb->updateInvoice($iItemId, array('status' => BX_PAYMENT_INV_STATUS_PAID)))
  1296. return array();
  1297. bx_alert($this->getName(), 'invoice_marked_as_paid', 0, false, array(
  1298. 'product_id' => $iItemId,
  1299. 'profile_id' => $iClientId,
  1300. 'order' => $sOrder,
  1301. 'license' => $sLicense,
  1302. 'type' => BX_PAYMENT_TYPE_SINGLE,
  1303. 'count' => $iItemCount,
  1304. 'duration' => '',
  1305. 'trial' => ''
  1306. ));
  1307. return $aItem;
  1308. }
  1309. /**
  1310. * @page service Service Calls
  1311. * @section bx_payment Payment
  1312. * @subsection bx_payment-payments Payments
  1313. * @subsubsection bx_payment-unregister_cart_item unregister_cart_item
  1314. *
  1315. * @code bx_srv('bx_payment', 'unregister_cart_item', [...]); @endcode
  1316. *
  1317. * Unregister an earlier processed single time payment inside the Payment module. Is called with payment processing module after the payment was unregistered there.
  1318. *
  1319. * @param $iClientId client ID.
  1320. * @param $iSellerId seller ID
  1321. * @param $iItemId item ID.
  1322. * @param $iItemCount the number of purchased items.
  1323. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  1324. * @param $sLicense license number genereted with payment processing module for internal usage
  1325. * @return boolean value determining where the payment was unregistered or not.
  1326. *
  1327. * @see BxPaymentModule::serviceUnregisterCartItem
  1328. */
  1329. /**
  1330. * @ref bx_payment-unregister_cart_item "unregister_cart_item"
  1331. */
  1332. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  1333. {
  1334. if(!$this->_oDb->updateInvoice($iItemId, array('status' => BX_PAYMENT_INV_STATUS_UNPAID)))
  1335. return false;
  1336. bx_alert($this->getName(), 'invoice_marked_as_unpaid', 0, false, array(
  1337. 'product_id' => $iItemId,
  1338. 'profile_id' => $iClientId,
  1339. 'order' => $sOrder,
  1340. 'license' => $sLicense,
  1341. 'type' => BX_PAYMENT_TYPE_SINGLE,
  1342. 'count' => $iItemCount
  1343. ));
  1344. return true;
  1345. }
  1346. }
  1347. /** @} */