NoteMultiCurrencyAvailable.php
2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Notify merchant that Multi-Currency is available.
*
* @package WooCommerce\Payments\MultiCurrency
*/
namespace WCPay\MultiCurrency\Notes;
use Automattic\WooCommerce\Admin\Notes\Note;
use Automattic\WooCommerce\Admin\Notes\NoteTraits;
use WC_Payments_Account;
defined( 'ABSPATH' ) || exit;
/**
* Class NoteMultiCurrencyAvailable
*/
class NoteMultiCurrencyAvailable {
use NoteTraits;
/**
* Name of the note for use in the database.
*/
const NOTE_NAME = 'wc-payments-notes-multi-currency-available';
/**
* Url to start the setup process. Now redirects to the wizard page.
*/
// TODO: Proper url needed for setup process.
const NOTE_SETUP_URL = 'admin.php?page=wc-admin&path=/payments/multi-currency-setup';
/**
* The account service instance.
*
* @var WC_Payments_Account
*/
private static $account;
/**
* Get the note.
*/
public static function get_note() {
$note = new Note();
$note->set_title( __( 'Sell worldwide in multiple currencies', 'woocommerce-payments' ) );
$note->set_content( __( 'Boost your international sales by allowing your customers to shop and pay in their local currency.', 'woocommerce-payments' ) );
$note->set_content_data( (object) [] );
$note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
$note->set_name( self::NOTE_NAME );
$note->set_source( 'woocommerce-payments' );
$note->add_action(
self::NOTE_NAME,
__( 'Set up now', 'woocommerce-payments' ),
self::NOTE_SETUP_URL,
'unactioned',
true
);
return $note;
}
/**
* Add the note if it passes predefined conditions.
*/
public static function possibly_add_note() {
// Don't add the note if the merchant didn't create a WCPay account yet.
if ( is_null( self::$account ) || ! self::$account->is_stripe_connected() ) {
return;
}
if ( ! self::can_be_added() ) {
return;
}
$note = self::get_note();
$note->save();
}
/**
* Sets the account service instance reference on the class.
*
* @param WC_Payments_Account $account account service instance.
*/
public static function set_account( WC_Payments_Account $account ) {
self::$account = $account;
}
}