| 1 |
<?php |
| 2 |
/** |
| 3 |
* Ebook Store - Adyen settings tab. |
| 4 |
* |
| 5 |
* Rendered inside <div class="ebook-settings-panel">, so this file emits |
| 6 |
* <section> blocks directly. No table markup. |
| 7 |
* |
| 8 |
* PHP 7.4 compatible. |
| 9 |
* |
| 10 |
* @package EbookStore |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
settings_fields( 'ebook-settings-group-adyen' ); |
| 18 |
do_settings_sections( 'ebook-settings-group-adyen' ); |
| 19 |
|
| 20 |
$api_key = (string) get_option( 'adyen_api_key', '' ); |
| 21 |
$merchant_account = (string) get_option( 'adyen_merchant_account', '' ); |
| 22 |
$hmac_key = (string) get_option( 'adyen_hmac_key', '' ); |
| 23 |
$environment = (string) get_option( 'adyen_environment', 'test' ); |
| 24 |
$live_prefix = (string) get_option( 'adyen_live_prefix', '' ); |
| 25 |
$integration_enabled = (string) get_option( 'adyen_integration_enabled', '' ); |
| 26 |
|
| 27 |
$is_live = ( $environment === 'live' ); |
| 28 |
$missing_prefix = ( $is_live && trim( $live_prefix ) === '' ); |
| 29 |
$webhook_url = site_url( 'wp-json/ebook-store/v1/adyen-webhook' ); |
| 30 |
$general_tab_url = ebook_store_get_settings_tab_url( 'General' ); |
| 31 |
?> |
| 32 |
|
| 33 |
<?php |
| 34 |
ebook_store_render_hero( |
| 35 |
array( |
| 36 |
'eyebrow' => __( 'Adyen', 'ebook-store' ), |
| 37 |
'title' => __( 'Take card payments through Adyen Pay by Link', 'ebook-store' ), |
| 38 |
'intro' => __( 'Buyers pay on a secure Adyen page and come straight back to your shop. Adyen then tells this site that the payment went through, and the ebook download is released automatically.', 'ebook-store' ), |
| 39 |
'aside' => function () use ( $is_live, $missing_prefix, $api_key, $merchant_account, $hmac_key, $integration_enabled ) { |
| 40 |
?> |
| 41 |
<aside class="ebook-settings-status-card"> |
| 42 |
<h4><?php echo esc_html__( 'Current status', 'ebook-store' ); ?></h4> |
| 43 |
<ul class="ebook-settings-status-list"> |
| 44 |
<?php |
| 45 |
ebook_store_status_row( |
| 46 |
__( 'Adyen payment button', 'ebook-store' ), |
| 47 |
$integration_enabled === '1' ? 'ok' : 'muted', |
| 48 |
$integration_enabled === '1' |
| 49 |
? __( 'On. Buyers can choose Adyen at checkout.', 'ebook-store' ) |
| 50 |
: __( 'Off. Buyers will not see an Adyen button.', 'ebook-store' ) |
| 51 |
); |
| 52 |
|
| 53 |
ebook_store_status_row( |
| 54 |
$is_live |
| 55 |
? __( 'Mode: Live', 'ebook-store' ) |
| 56 |
: __( 'Mode: Test', 'ebook-store' ), |
| 57 |
$is_live ? 'ok' : 'warn', |
| 58 |
$is_live |
| 59 |
? __( 'Real money is charged to your buyers.', 'ebook-store' ) |
| 60 |
: __( 'Test mode. No real money changes hands yet.', 'ebook-store' ) |
| 61 |
); |
| 62 |
|
| 63 |
ebook_store_status_row( |
| 64 |
__( 'API key', 'ebook-store' ), |
| 65 |
trim( $api_key ) !== '' ? 'ok' : 'error', |
| 66 |
trim( $api_key ) !== '' |
| 67 |
? __( 'Saved.', 'ebook-store' ) |
| 68 |
: __( 'Missing. Adyen cannot create payment pages without it.', 'ebook-store' ) |
| 69 |
); |
| 70 |
|
| 71 |
ebook_store_status_row( |
| 72 |
__( 'Merchant account', 'ebook-store' ), |
| 73 |
trim( $merchant_account ) !== '' ? 'ok' : 'error', |
| 74 |
trim( $merchant_account ) !== '' |
| 75 |
? __( 'Saved.', 'ebook-store' ) |
| 76 |
: __( 'Missing. Adyen needs to know which account gets paid.', 'ebook-store' ) |
| 77 |
); |
| 78 |
|
| 79 |
ebook_store_status_row( |
| 80 |
__( 'Webhook HMAC key', 'ebook-store' ), |
| 81 |
trim( $hmac_key ) !== '' ? 'ok' : 'error', |
| 82 |
trim( $hmac_key ) !== '' |
| 83 |
? __( 'Saved.', 'ebook-store' ) |
| 84 |
: __( 'Missing. Paid orders will not be confirmed automatically.', 'ebook-store' ) |
| 85 |
); |
| 86 |
|
| 87 |
if ( $missing_prefix ) { |
| 88 |
ebook_store_status_row( |
| 89 |
__( 'Live URL prefix', 'ebook-store' ), |
| 90 |
'error', |
| 91 |
__( 'Missing. In Live mode every payment attempt will fail until you add it.', 'ebook-store' ) |
| 92 |
); |
| 93 |
} elseif ( $is_live ) { |
| 94 |
ebook_store_status_row( |
| 95 |
__( 'Live URL prefix', 'ebook-store' ), |
| 96 |
'ok', |
| 97 |
__( 'Saved.', 'ebook-store' ) |
| 98 |
); |
| 99 |
} |
| 100 |
?> |
| 101 |
</ul> |
| 102 |
</aside> |
| 103 |
<?php |
| 104 |
}, |
| 105 |
) |
| 106 |
); |
| 107 |
|
| 108 |
ebook_store_pro_banner( __( 'Adyen', 'ebook-store' ) ); |
| 109 |
|
| 110 |
if ( $missing_prefix ) { |
| 111 |
ebook_store_callout( |
| 112 |
__( 'Adyen is set to Live but the live URL prefix below is empty. Adyen will reject every payment until you copy that prefix from your Adyen account.', 'ebook-store' ), |
| 113 |
'warning', |
| 114 |
__( 'Action needed:', 'ebook-store' ) |
| 115 |
); |
| 116 |
} |
| 117 |
?> |
| 118 |
|
| 119 |
<?php |
| 120 |
ebook_store_section_open( |
| 121 |
array( |
| 122 |
'eyebrow' => __( 'Checkout', 'ebook-store' ), |
| 123 |
'title' => __( 'Turn Adyen on and choose the button wording', 'ebook-store' ), |
| 124 |
'intro' => __( 'Switch Adyen on once the account details further down this page are filled in and saved. Then decide what the payment button says to your buyers.', 'ebook-store' ), |
| 125 |
'id' => 'ebook-adyen-checkout', |
| 126 |
'pro' => true, |
| 127 |
) |
| 128 |
); |
| 129 |
|
| 130 |
ebook_store_toggle_grid_open(); |
| 131 |
ebook_store_toggle( |
| 132 |
array( |
| 133 |
'name' => 'adyen_integration_enabled', |
| 134 |
'id' => 'adyen_integration_enabled', |
| 135 |
'title' => __( 'Offer Adyen at checkout', 'ebook-store' ), |
| 136 |
'description' => __( 'Shows the Adyen button on your ebook pages. It only works once the API key, merchant account and webhook HMAC key below are saved.', 'ebook-store' ), |
| 137 |
'checked' => $integration_enabled, |
| 138 |
'pro' => true, |
| 139 |
) |
| 140 |
); |
| 141 |
ebook_store_toggle_grid_close(); |
| 142 |
|
| 143 |
ebook_store_advanced_open(); |
| 144 |
ebook_store_render_gateway_button_text( 'adyen' ); |
| 145 |
ebook_store_advanced_close(); |
| 146 |
|
| 147 |
ebook_store_section_close(); |
| 148 |
?> |
| 149 |
|
| 150 |
<?php |
| 151 |
ebook_store_section_open( |
| 152 |
array( |
| 153 |
'eyebrow' => __( 'Adyen account', 'ebook-store' ), |
| 154 |
'title' => __( 'Your Adyen credentials', 'ebook-store' ), |
| 155 |
'intro' => __( 'These values come from your Adyen Customer Area. Test and Live are two completely separate accounts, so always copy all of the values from the same one.', 'ebook-store' ), |
| 156 |
'id' => 'ebook-adyen-credentials', |
| 157 |
'pro' => true, |
| 158 |
) |
| 159 |
); |
| 160 |
|
| 161 |
ebook_store_grid_open( 2 ); |
| 162 |
|
| 163 |
ebook_store_field( |
| 164 |
array( |
| 165 |
'type' => 'select', |
| 166 |
'name' => 'adyen_environment', |
| 167 |
'id' => 'adyen_environment', |
| 168 |
'label' => __( 'Mode', 'ebook-store' ), |
| 169 |
'value' => $environment, |
| 170 |
'options' => array( |
| 171 |
'test' => __( 'Test - practise payments, no real money', 'ebook-store' ), |
| 172 |
'live' => __( 'Live - real payments from real buyers', 'ebook-store' ), |
| 173 |
), |
| 174 |
'pro' => true, |
| 175 |
'help' => __( 'Stay on Test until you have made a successful practice purchase. Switch to Live only after you have entered your live API key, your live URL prefix, and set up the webhook in your live Adyen account.', 'ebook-store' ), |
| 176 |
) |
| 177 |
); |
| 178 |
|
| 179 |
ebook_store_field( |
| 180 |
array( |
| 181 |
'type' => 'text', |
| 182 |
'name' => 'adyen_merchant_account', |
| 183 |
'id' => 'adyen_merchant_account', |
| 184 |
'label' => __( 'Merchant account name', 'ebook-store' ), |
| 185 |
'value' => $merchant_account, |
| 186 |
'placeholder' => 'YourMerchantAccount', |
| 187 |
'mono' => true, |
| 188 |
'pro' => true, |
| 189 |
'help' => __( 'The name of the Adyen account that should receive your ebook payments. In the Adyen Customer Area it is shown in the account switcher at the top of the page. Type it exactly as Adyen writes it, including capital letters. A wrong name means Adyen refuses the payment.', 'ebook-store' ), |
| 190 |
'note' => trim( $merchant_account ) === '' ? __( 'Adyen payments cannot start until this is filled in.', 'ebook-store' ) : '', |
| 191 |
'note_tone' => 'warning', |
| 192 |
) |
| 193 |
); |
| 194 |
|
| 195 |
ebook_store_field( |
| 196 |
array( |
| 197 |
'type' => 'text', |
| 198 |
'name' => 'adyen_api_key', |
| 199 |
'id' => 'adyen_api_key', |
| 200 |
'label' => __( 'API key', 'ebook-store' ), |
| 201 |
'value' => $api_key, |
| 202 |
'placeholder' => 'AQEy...', |
| 203 |
'mono' => true, |
| 204 |
'wide' => true, |
| 205 |
'pro' => true, |
| 206 |
'help' => __( 'In the Adyen Customer Area go to Developers, then API credentials, and generate a Checkout API key. Copy it here straight away - Adyen only shows it once. Keep it secret: anyone with this key can take payments in your name.', 'ebook-store' ), |
| 207 |
'note' => trim( $api_key ) === '' ? __( 'Adyen payments cannot start until this is filled in.', 'ebook-store' ) : '', |
| 208 |
'note_tone' => 'warning', |
| 209 |
) |
| 210 |
); |
| 211 |
|
| 212 |
ebook_store_grid_close(); |
| 213 |
|
| 214 |
ebook_store_advanced_open(); |
| 215 |
|
| 216 |
ebook_store_grid_open( 2 ); |
| 217 |
|
| 218 |
ebook_store_field( |
| 219 |
array( |
| 220 |
'type' => 'text', |
| 221 |
'name' => 'adyen_live_prefix', |
| 222 |
'id' => 'adyen_live_prefix', |
| 223 |
'label' => __( 'Live URL prefix (Live mode only)', 'ebook-store' ), |
| 224 |
'value' => $live_prefix, |
| 225 |
'placeholder' => '1797a841fbb37ca7-AdyenDemo', |
| 226 |
'mono' => true, |
| 227 |
'wide' => true, |
| 228 |
'pro' => true, |
| 229 |
'help' => __( 'Only needed when Mode is set to Live. Adyen gives every live account its own web address. Find it in the Customer Area under Developers, then API URLs, and copy the short code in front of the Adyen address - not the whole address.', 'ebook-store' ), |
| 230 |
'note' => $missing_prefix ? __( 'Mode is Live and this is empty, so every payment will fail. Add the prefix or switch back to Test.', 'ebook-store' ) : '', |
| 231 |
'note_tone' => 'error', |
| 232 |
) |
| 233 |
); |
| 234 |
|
| 235 |
ebook_store_grid_close(); |
| 236 |
|
| 237 |
ebook_store_advanced_close(); |
| 238 |
|
| 239 |
ebook_store_callout( |
| 240 |
sprintf( |
| 241 |
/* translators: %s: link to the General settings tab. */ |
| 242 |
__( 'Adyen is part of Ebook Store Pro. Your settings are saved either way, but the Adyen button only appears once a Pro license key is saved on the <a href="%s">General tab</a>.', 'ebook-store' ), |
| 243 |
esc_url( $general_tab_url ) |
| 244 |
), |
| 245 |
'info' |
| 246 |
); |
| 247 |
|
| 248 |
ebook_store_section_close(); |
| 249 |
?> |
| 250 |
|
| 251 |
<?php |
| 252 |
ebook_store_section_open( |
| 253 |
array( |
| 254 |
'eyebrow' => __( 'Payment confirmation', 'ebook-store' ), |
| 255 |
'title' => __( 'Let Adyen tell your shop when a payment succeeds', 'ebook-store' ), |
| 256 |
'intro' => __( 'Adyen sends a message to your website after each payment. Your shop checks that the message really came from Adyen, and only then creates the order and releases the download.', 'ebook-store' ), |
| 257 |
'id' => 'ebook-adyen-webhook', |
| 258 |
'pro' => true, |
| 259 |
) |
| 260 |
); |
| 261 |
|
| 262 |
ebook_store_advanced_open( __( 'Advanced webhook settings', 'ebook-store' ) ); |
| 263 |
|
| 264 |
ebook_store_copy_box( |
| 265 |
$webhook_url, |
| 266 |
__( 'Webhook address to paste into Adyen', 'ebook-store' ), |
| 267 |
__( 'In the Adyen Customer Area go to Developers, then Webhooks, and add a Standard webhook using this address. Leave the AUTHORISATION event switched on - that is the one that tells your shop a payment succeeded.', 'ebook-store' ) |
| 268 |
); |
| 269 |
|
| 270 |
ebook_store_grid_open( 2 ); |
| 271 |
|
| 272 |
ebook_store_field( |
| 273 |
array( |
| 274 |
'type' => 'text', |
| 275 |
'name' => 'adyen_hmac_key', |
| 276 |
'id' => 'adyen_hmac_key', |
| 277 |
'label' => __( 'Webhook HMAC key', 'ebook-store' ), |
| 278 |
'value' => $hmac_key, |
| 279 |
'placeholder' => 'A1B2C3D4E5F6...', |
| 280 |
'mono' => true, |
| 281 |
'wide' => true, |
| 282 |
'pro' => true, |
| 283 |
'help' => __( 'On the same Adyen webhook screen, generate the HMAC key and paste it here. It is the shared password that proves a message really came from Adyen. If it is missing or wrong, your buyers will pay but no order will be created.', 'ebook-store' ), |
| 284 |
'note' => trim( $hmac_key ) === '' ? __( 'Without this key, paid orders will not be confirmed automatically.', 'ebook-store' ) : '', |
| 285 |
'note_tone' => 'warning', |
| 286 |
) |
| 287 |
); |
| 288 |
|
| 289 |
ebook_store_grid_close(); |
| 290 |
|
| 291 |
ebook_store_callout( |
| 292 |
__( 'Each Adyen account has its own webhook. If you switch from Test to Live, set the webhook up again in your live account and paste the new HMAC key here.', 'ebook-store' ), |
| 293 |
'warning' |
| 294 |
); |
| 295 |
|
| 296 |
ebook_store_advanced_close(); |
| 297 |
|
| 298 |
ebook_store_section_close(); |
| 299 |
?> |
| 300 |
|
| 301 |
<?php |
| 302 |
ebook_store_section_open( |
| 303 |
array( |
| 304 |
'eyebrow' => __( 'Setup guide', 'ebook-store' ), |
| 305 |
'title' => __( 'Setting Adyen up, step by step', 'ebook-store' ), |
| 306 |
'intro' => __( 'Work through these in order. Turning Adyen on before the credentials are saved is the most common cause of failed checkouts.', 'ebook-store' ), |
| 307 |
'id' => 'ebook-adyen-steps', |
| 308 |
) |
| 309 |
); |
| 310 |
|
| 311 |
ebook_store_steps( |
| 312 |
__( 'From empty account to first sale', 'ebook-store' ), |
| 313 |
array( |
| 314 |
__( 'Sign in to your Adyen Customer Area, or sign up for a test account.', 'ebook-store' ), |
| 315 |
__( 'Create a Checkout API key and copy the merchant account name, then paste both into the fields above.', 'ebook-store' ), |
| 316 |
__( 'Add a Standard webhook in Adyen using the address shown on this page, and paste its HMAC key above.', 'ebook-store' ), |
| 317 |
__( 'Leave Mode on Test, switch Adyen on, and buy one of your own ebooks with an Adyen test card to check the whole flow.', 'ebook-store' ), |
| 318 |
__( 'When the test purchase works, repeat the API key, merchant account and webhook steps in your live Adyen account, add the live URL prefix, and switch Mode to Live.', 'ebook-store' ), |
| 319 |
) |
| 320 |
); |
| 321 |
|
| 322 |
ebook_store_section_close(); |
| 323 |
|