Passed
Push — develop-3.3.x ( 26c82c...08c99e )
by Mario
05:09 queued 02:39
created

transaction_template_helper::assign_user_data()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * PayPal Donation extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2015-2021 Skouat
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace skouat\ppde\helpers;
12
13
use phpbb\template\template;
14
use phpbb\language\language;
15
use phpbb\user;
16
use skouat\ppde\actions\currency;
17
18
class transaction_template_helper
19
{
20
	protected $actions_currency;
21
	protected $language;
22
	protected $template;
23
	protected $user;
24
	protected $phpbb_admin_path;
25
	protected $php_ext;
26
27
	/**
28
	 * Constructor
29
	 *
30
	 * @param template $template
31
	 * @param language $language
32
	 * @param user     $user
33
	 * @param currency $actions_currency
34
	 * @param string   $adm_relative_path
35
	 * @param string   $phpbb_root_path
36
	 * @param string   $php_ext
37
	 */
38
	public function __construct(
39
		template $template,
40
		language $language,
41
		user $user,
42
		currency $actions_currency,
43
		string $adm_relative_path,
44
		string $phpbb_root_path,
45
		string $php_ext
46
	)
47
	{
48
		$this->template = $template;
49
		$this->language = $language;
50
		$this->user = $user;
51
		$this->actions_currency = $actions_currency;
52
		$this->phpbb_admin_path = $phpbb_root_path . $adm_relative_path;
53
		$this->php_ext = $php_ext;
54
	}
55
56
	/**
57
	 * Assign hidden fields
58
	 *
59
	 * @param array $data
60
	 */
61
	public function assign_hidden_fields(array $data): void
62
	{
63
		$s_hidden_fields = build_hidden_fields([
64
			'id'                  => $data['transaction_id'],
65
			'donor_id'            => $data['user_id'],
66
			'txn_errors_approved' => $data['txn_errors_approved'],
67
		]);
68
		$this->template->assign_var('S_HIDDEN_FIELDS', $s_hidden_fields);
69
	}
70
71
	/**
72
	 * Assign currency data to template variables
73
	 *
74
	 * @param array $data Transaction data
75
	 */
76
	public function assign_currency_data(array $data): void
77
	{
78
		$this->actions_currency->set_currency_data_from_iso_code($data['mc_currency']);
79
		$this->actions_currency->set_currency_data_from_iso_code($data['settle_currency']);
80
81
		$this->template->assign_vars([
82
			'EXCHANGE_RATE'                   => '1 ' . $data['mc_currency'] . ' = ' . $data['exchange_rate'] . ' ' . $data['settle_currency'],
83
			'MC_GROSS'                        => $this->actions_currency->format_currency($data['mc_gross']),
84
			'MC_FEE'                          => $this->actions_currency->format_currency($data['mc_fee']),
85
			'MC_NET'                          => $this->actions_currency->format_currency($data['net_amount']),
86
			'SETTLE_AMOUNT'                   => $this->actions_currency->format_currency($data['settle_amount']),
87
			'L_PPDE_DT_SETTLE_AMOUNT'         => $this->language->lang('PPDE_DT_SETTLE_AMOUNT', $data['settle_currency']),
88
			'L_PPDE_DT_EXCHANGE_RATE_EXPLAIN' => $this->language->lang('PPDE_DT_EXCHANGE_RATE_EXPLAIN', $this->user->format_date($data['payment_date'])),
89
			'S_CONVERT'                       => !((int) $data['settle_amount'] === 0 && empty($data['exchange_rate'])),
90
		]);
91
	}
92
93
	/**
94
	 * Assign user data to template variables
95
	 *
96
	 * @param array $data Transaction data
97
	 */
98
	public function assign_user_data(array $data): void
99
	{
100
		$this->template->assign_vars([
101
			'BOARD_USERNAME' => get_username_string('full', $data['user_id'], $data['username'], $data['user_colour'], $this->language->lang('GUEST'), append_sid($this->phpbb_admin_path . 'index.' . $this->php_ext, 'i=users&amp;mode=overview')),
102
			'NAME'           => $data['first_name'] . ' ' . $data['last_name'],
103
			'PAYER_EMAIL'    => $data['payer_email'],
104
			'PAYER_ID'       => $data['payer_id'],
105
			'PAYER_STATUS'   => $data['payer_status'] ? $this->language->lang('PPDE_DT_VERIFIED') : $this->language->lang('PPDE_DT_UNVERIFIED'),
106
		]);
107
	}
108
109
	/**
110
	 * Assign transaction details to template variables
111
	 *
112
	 * @param array $data Transaction data
113
	 */
114
	public function assign_transaction_details(array $data): void
115
	{
116
		$this->template->assign_vars([
117
			'ITEM_NAME'      => $data['item_name'],
118
			'ITEM_NUMBER'    => $data['item_number'],
119
			'MEMO'           => $data['memo'],
120
			'RECEIVER_EMAIL' => $data['receiver_email'],
121
			'RECEIVER_ID'    => $data['receiver_id'],
122
			'TXN_ID'         => $data['txn_id'],
123
		]);
124
	}
125
126
	/**
127
	 * Assign payment details to template variables
128
	 *
129
	 * @param array $data Transaction data
130
	 */
131
	public function assign_payment_details(array $data): void
132
	{
133
		$this->template->assign_vars([
134
			'PAYMENT_DATE'   => $this->user->format_date($data['payment_date']),
135
			'PAYMENT_STATUS' => $this->language->lang(['PPDE_DT_PAYMENT_STATUS_VALUES', strtolower($data['payment_status'])]),
136
		]);
137
	}
138
139
	/**
140
	 * Assign error data to template variables
141
	 *
142
	 * @param array $data Transaction data
143
	 */
144
	public function assign_error_data(array $data): void
145
	{
146
		$this->template->assign_vars([
147
			'S_ERROR'          => !empty($data['txn_errors']),
148
			'S_ERROR_APPROVED' => !empty($data['txn_errors_approved']),
149
			'ERROR_MSG'        => (!empty($data['txn_errors'])) ? $data['txn_errors'] : '',
150
		]);
151
	}
152
}
153