| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Description of Account |
| 5 |
* |
| 6 |
* @author Ali2Woo Team |
| 7 |
*/ |
| 8 |
namespace AliNext_Lite;; |
| 9 |
|
| 10 |
class Account { |
| 11 |
private static $_instance = null; |
| 12 |
|
| 13 |
public $account_type = ''; |
| 14 |
public $custom_account = false; |
| 15 |
|
| 16 |
public $account_data = array('aliexpress'=>array('appkey'=>'', 'secretkey'=>'', 'trackingid'=>''), |
| 17 |
'admitad'=>array('cashback_url'=>'', 'account_name' => ''), |
| 18 |
'epn'=>array('cashback_url'=>'')); |
| 19 |
|
| 20 |
|
| 21 |
static public function getInstance() { |
| 22 |
if (is_null(self::$_instance)) { |
| 23 |
self::$_instance = new self(); |
| 24 |
} |
| 25 |
return self::$_instance; |
| 26 |
} |
| 27 |
|
| 28 |
protected function __construct() { |
| 29 |
$this->account_type = get_setting('account_type'); |
| 30 |
$this->custom_account = get_setting('use_custom_account'); |
| 31 |
$this->account_data = get_setting('account_data'); |
| 32 |
} |
| 33 |
|
| 34 |
public function set_account_type($account_type) { |
| 35 |
$this->account_type = $account_type; |
| 36 |
set_setting('account_type', $this->account_type); |
| 37 |
} |
| 38 |
|
| 39 |
public function use_custom_account($use_custom_account = false) { |
| 40 |
$this->custom_account = $use_custom_account; |
| 41 |
set_setting('use_custom_account', $this->custom_account); |
| 42 |
} |
| 43 |
|
| 44 |
public function get_aliexpress_account(): array |
| 45 |
{ |
| 46 |
$account = [ |
| 47 |
'appkey' => '', |
| 48 |
'secretkey' => '', |
| 49 |
'trackingid' => '' |
| 50 |
]; |
| 51 |
|
| 52 |
if (!empty($this->account_data['aliexpress'])) { |
| 53 |
$account = $this->account_data['aliexpress']; |
| 54 |
} |
| 55 |
|
| 56 |
return $account; |
| 57 |
} |
| 58 |
|
| 59 |
public function get_admitad_account() { |
| 60 |
return !empty($this->account_data['admitad'])?$this->account_data['admitad']:array('cashback_url'=>'', 'account_name' => ''); |
| 61 |
} |
| 62 |
|
| 63 |
public function get_epn_account() { |
| 64 |
return !empty($this->account_data['epn'])?$this->account_data['epn']:array('cashback_url'=>''); |
| 65 |
} |
| 66 |
|
| 67 |
public function save_aliexpress_account(?string $appkey, ?string $secretkey, ?string $trackingid): void |
| 68 |
{ |
| 69 |
$this->account_data['aliexpress']['appkey'] = $appkey; |
| 70 |
$this->account_data['aliexpress']['secretkey'] = $secretkey; |
| 71 |
$this->account_data['aliexpress']['trackingid'] = $trackingid; |
| 72 |
set_setting('account_data', $this->account_data); |
| 73 |
} |
| 74 |
|
| 75 |
public function save_admitad_account($cashback_url, $account_name) { |
| 76 |
$this->account_data['admitad']['cashback_url']=$cashback_url; |
| 77 |
$this->account_data['admitad']['account_name']=$account_name; |
| 78 |
|
| 79 |
set_setting('account_data', $this->account_data); |
| 80 |
} |
| 81 |
|
| 82 |
public function save_epn_account($cashback_url) { |
| 83 |
$this->account_data['epn']['cashback_url']=$cashback_url; |
| 84 |
|
| 85 |
set_setting('account_data', $this->account_data); |
| 86 |
} |
| 87 |
|
| 88 |
public function get_purchase_code() { |
| 89 |
if (a2wl_check_defined('A2WL_ITEM_PURCHASE_CODE')) { |
| 90 |
return A2WL_ITEM_PURCHASE_CODE; |
| 91 |
} else { |
| 92 |
return get_setting('item_purchase_code'); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
public function build_params(){ |
| 97 |
$item_purchase_code = $this->get_purchase_code(); |
| 98 |
|
| 99 |
$result="token=".urlencode($item_purchase_code)."&version=".A2WL()->version; |
| 100 |
|
| 101 |
if(!empty( $this->account_data['admitad']['cashback_url'])){ |
| 102 |
$result.="&cashback_url=". urlencode($this->account_data['admitad']['cashback_url']) . |
| 103 |
"&account_name=". urlencode($this->account_data['admitad']['account_name']); |
| 104 |
} |
| 105 |
|
| 106 |
return $result; |
| 107 |
} |
| 108 |
|
| 109 |
public function is_activated(){ |
| 110 |
$item_purchase_code = a2wl_check_defined('A2WL_ITEM_PURCHASE_CODE')?A2WL_ITEM_PURCHASE_CODE:get_setting('item_purchase_code'); |
| 111 |
return !empty($item_purchase_code); |
| 112 |
} |
| 113 |
} |
| 114 |
|