LLMS_Notification_View_Upcoming_Payment_Reminder

Notification View: Payment Retry.


Source Source

File: includes/notifications/views/class.llms.notification.view.upcoming.payment.reminder.php

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
class LLMS_Notification_View_Upcoming_Payment_Reminder extends LLMS_Abstract_Notification_View {
 
    /**
     * Settings for basic notifications.
     *
     * @var array
     */
    protected $basic_options = array(
        /**
         * Time in milliseconds to show a notification
         * before automatically dismissing it.
         */
        'auto_dismiss' => 10000,
        /**
         * Enables manual dismissal of notifications.
         */
        'dismissible'  => true,
    );
 
 
    /**
     * Notification Trigger ID.
     *
     * @var string
     */
    public $trigger_id = 'upcoming_payment_reminder';
 
    /**
     * Setup body content for output.
     *
     * @since 5.2.0
     *
     * @return string
     */
    protected function set_body() {
 
        if ( 'email' === $this->notification->get( 'type' ) ) {
            return $this->set_body_email();
        }
        return $this->set_body_basic();
 
    }
 
    /**
     * Setup default notification body for basic notifications.
     *
     * @since 5.2.0
     *
     * @return string
     */
    private function set_body_basic() {
        return sprintf( esc_html__( 'You will be charged for your subscription to %1$s tomorrow.', 'lifterlms' ), '{{PRODUCT_TITLE}}' );
    }
 
    /**
     * Setup default notification body for email notifications.
     *
     * @since 5.2.0
     *
     * @return string
     */
    private function set_body_email() {
 
        $mailer = llms()->mailer();
 
        $rows = array(
            'NEXT_PAYMENT_DATE'  => __( 'Payment Due Date', 'lifterlms' ),
            'PRODUCT_TITLE_LINK' => '{{PRODUCT_TYPE}}',
            'PLAN_TITLE'         => __( 'Plan', 'lifterlms' ),
            'PAYMENT_AMOUNT'     => __( 'Amount', 'lifterlms' ),
        );
 
        ob_start();
        ?>
        <p>
        <?php
            // Translators: %s= The customer name.
            printf( __( 'Hello %s,', 'lifterlms' ), '{{CUSTOMER_NAME}}' );
        ?>
        </p>
        <p>
        <?php
            // Translators: %1$s = The product title, %2$s The upcoming payment due date.
            printf( __( 'You will be charged for your subscription to %1$s on %2$s.', 'lifterlms' ), '{{PRODUCT_TITLE}}', '{{NEXT_PAYMENT_DATE}}' );
        ?>
        </p>
        <h4>
        <?php
            // Translators: %s= The order ID.
            printf( __( 'Order #%s', 'lifterlms' ), '{{ORDER_ID}}' );
        ?>
        </h4>
        <?php echo $mailer->get_table_html( $rows ); ?>
        <p><a href="{{ORDER_URL}}"><?php _e( 'Update Payment Method', 'lifterlms' ); ?></a></p>
        <?php
        return ob_get_clean();
    }
 
    /**
     * Setup footer content for output.
     *
     * @since 5.2.0
     *
     * @return string
     */
    protected function set_footer() {
        $url = $this->set_merge_data( '{{ORDER_URL}}' );
        return '<a href="' . esc_url( $url ) . '">' . esc_html__( 'Update Payment Method', 'lifterlms' ) . '</a>';
    }
 
    /**
     * Setup notification icon for output.
     *
     * @since 5.2.0
     *
     * @return string
     */
    protected function set_icon() {
        return $this->get_icon_default( 'warning' );
    }
 
    /**
     * Setup merge codes that can be used with the notification.
     *
     * @since 5.2.0
     *
     * @return array
     */
    protected function set_merge_codes() {
        return array(
            '{{CUSTOMER_ADDRESS}}'   => __( 'Customer Address', 'lifterlms' ),
            '{{CUSTOMER_NAME}}'      => __( 'Customer Name', 'lifterlms' ),
            '{{CUSTOMER_PHONE}}'     => __( 'Customer Phone', 'lifterlms' ),
            '{{NEXT_PAYMENT_DATE}}'  => __( 'Next Payment Date', 'lifterlms' ),
            '{{ORDER_ID}}'           => __( 'Order ID', 'lifterlms' ),
            '{{ORDER_URL}}'          => __( 'Order URL', 'lifterlms' ),
            '{{PAYMENT_AMOUNT}}'     => __( 'Payment Amount', 'lifterlms' ),
            '{{PLAN_TITLE}}'         => __( 'Plan Title', 'lifterlms' ),
            '{{PRODUCT_TITLE}}'      => __( 'Product Title', 'lifterlms' ),
            '{{PRODUCT_TYPE}}'       => __( 'Product Type', 'lifterlms' ),
            '{{PRODUCT_TITLE_LINK}}' => __( 'Product Title (Link)', 'lifterlms' ),
        );
    }
 
    /**
     * Replace merge codes with actual values.
     *
     * @since 5.2.0
     * @since 5.4.0 Account for deleted products.
     *
     * @param string $code The merge code to get merged data for.
     * @return string
     */
    protected function set_merge_data( $code ) {
 
        $order = $this->post;
 
        switch ( $code ) {
 
            case '{{CUSTOMER_ADDRESS}}':
                $code = $order->get_customer_full_address();
                break;
 
            case '{{CUSTOMER_NAME}}':
                $code = $order->get_customer_name();
                break;
 
            case '{{CUSTOMER_PHONE}}':
                $code = $order->get( 'billing_phone' );
                break;
 
            case '{{NEXT_PAYMENT_DATE}}':
                $code = $order->get_date( 'date_next_payment', get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) );
                break;
 
            case '{{ORDER_ID}}':
                $code = $order->get( 'id' );
                break;
 
            case '{{ORDER_URL}}':
                $code = esc_url( $order->get_view_link() );
                break;
 
            case '{{PAYMENT_AMOUNT}}':
                $code = $order->get_price( 'total' );
                break;
 
            case '{{PLAN_TITLE}}':
                $code = $order->get( 'plan_title' );
                break;
 
            case '{{PRODUCT_TITLE}}':
                $code = $order->get( 'product_title' );
                break;
 
            case '{{PRODUCT_TITLE_LINK}}':
                $permalink = esc_url( get_permalink( $order->get( 'product_id' ) ) );
                if ( $permalink ) {
                    $title = $this->set_merge_data( '{{PRODUCT_TITLE}}' );
                    $code  = '<a href="' . $permalink . '">' . $title . '</a>';
                }
                break;
 
            case '{{PRODUCT_TYPE}}':
                $obj = $order->get_product();
                if ( empty( $obj ) ) {
                    $code = __( '[DELETED ITEM]', 'lifterlms' );
                } elseif ( is_a( $obj, 'WP_Post' ) ) {
                    $code = _x( 'Item', 'generic product type description', 'lifterlms' );
                } else {
                    $code = $obj->get_post_type_label( 'singular_name' );
                }
                break;
 
        }
 
        return $code;
 
    }
 
    /**
     * Setup notification subject for output.
     *
     * @since 5.2.0
     *
     * @return string
     */
    protected function set_subject() {
        // Translators: %s = The product title.
        return sprintf( __( 'Upcoming payment reminder for your subscription to %1$s', 'lifterlms' ), '{{PRODUCT_TITLE}}' );
    }
 
    /**
     * Setup notification title for output
     *
     * @since 5.2.0
     *
     * @return string
     */
    protected function set_title() {
        return __( 'Upcoming Subscription Payment', 'lifterlms' );
    }
 
}


Top ↑

Methods Methods


Top ↑

Changelog Changelog

Changelog
Version Description
5.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.