Plugin Directory

Changeset 2921565


Ignore:
Timestamp:
06/05/2023 10:42:21 AM (3 years ago)
Author:
bayarcash
Message:

Use author name Bayarcash instead of Web Impian Sdn. Bhd.

Location:
bayarcash-givewp
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • bayarcash-givewp/tags/3.0.0/bayarcash-givewp.php

    r2920974 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
     
    1515 * Version:             3.0.0
    1616 * Description:         Bayarcash payment plugin for GiveWP
    17  * Author:              Web Impian Sdn. Bhd.
     17 * Author:              Bayarcash
    1818 * Author URI:          https://bayarcash.com/?utm_source=wp-plugins-givewps&utm_campaign=author-uri&utm_medium=wp-dash
    1919 * Requires at least:   5.6
  • bayarcash-givewp/tags/3.0.0/includes/helpers.php

    r2920974 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/tags/3.0.0/includes/load.php

    r2920974 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/tags/3.0.0/includes/src/Bayarcash.php

    r2920974 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
     
    121121            }
    122122        });
     123
     124        // Must define before give_recurring is loaded.
     125        add_filter('give_recurring_available_gateways', function ($gateways) {
     126            $gateways['bayarcash'] = 'BayarCash\\GiveWP\\Givewp';
     127
     128            return $gateways;
     129        });
    123130    }
    124131
  • bayarcash-givewp/tags/3.0.0/includes/src/FpxApi.php

    r2920974 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/tags/3.0.0/includes/src/FpxCron.php

    r2920974 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/tags/3.0.0/includes/src/FpxDatabase.php

    r2920974 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/tags/3.0.0/includes/src/FpxResponseTransformer.php

    r2920974 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/tags/3.0.0/includes/src/FpxTransactionStatus.php

    r2920974 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/tags/3.0.0/includes/src/Givewp.php

    r2920974 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
     
    1313\defined('ABSPATH') || exit;
    1414
     15use Exception;
    1516use Give\Helpers\Form\Utils as FormUtils;
     17use Give_Donor;
     18use Give_Recurring_Subscriber;
     19use Give_Subscription;
    1620
    1721final class Givewp
     
    3034        $this->form_setups();
    3135        $this->payment_setups();
     36        $this->subscription_setups();
    3237        $this->pt->register_cronjob();
    3338    }
     
    213218    }
    214219
     220    private function subscription_setups()
     221    {
     222        add_action('give_checkout_error_checks', function ($valid_data) {
     223            $post_data = give_clean($_POST);
     224            if (!empty($post_data['give-gateway']) && 'bayarcash' !== $post_data['give-gateway']) {
     225                return;
     226            }
     227
     228            if (!is_user_logged_in() && !empty($post_data['give-form-id'])) {
     229                $form_id = absint($post_data['give-form-id']);
     230
     231                // Only required if email access not on & recurring enabled.
     232                if (give_is_form_recurring($form_id) && !give_is_setting_enabled(give_get_option('email_access'))) {
     233                    // check if form is recurring and create account checkbox should be checked.
     234                    if (!empty($post_data['_give_is_donation_recurring']) && empty($post_data['give_create_account'])) {
     235                        give_set_error('recurring_create_account', __('Please tick the create account button if you want to create a subscription donation', 'bayarcash-givewp'));
     236                    }
     237                }
     238            }
     239        }, 0, 1);
     240
     241        add_action('give_cancel_subscription', [$this, 'process_cancellation']);
     242        add_filter('give_subscription_can_cancel', [$this, 'can_cancel'], 10, 2);
     243        add_filter('give_subscription_can_sync', [$this, 'can_sync'], 10, 2);
     244        add_filter('give_subscription_can_update', [$this, 'can_update'], 10, 2);
     245        add_filter('give_subscription_can_update_subscription', [$this, 'can_update_subscription'], 10, 2);
     246
     247        add_filter('give_subscription_can_cancel_bayarcash_subscription', [
     248            $this,
     249            'can_cancel',
     250        ], 10, 2);
     251
     252        add_action('give_recurring_update_subscription_payment_method', [
     253            $this,
     254            'process_payment_method_update',
     255        ], 10, 3);
     256
     257        add_filter('give_subscription_profile_link_bayarcash', [$this, 'link_profile_id'], 10, 2);
     258        add_action('give_recurring_update_bayarcash_subscription', [$this, 'update_payment_method'], 10, 2);
     259
     260        add_action('give_recurring_update_renewal_subscription', [
     261            $this,
     262            'process_renewal_subscription_update',
     263        ], 10, 3);
     264        add_action('give_recurring_update_renewal_bayarcash_subscription', [$this, 'update_subscription'], 10, 2);
     265    }
     266
    215267    private function endpoint_tokens($form_id)
    216268    {
     
    263315        if (give_get_errors()) {
    264316            give_send_back_to_checkout('?payment-mode=bayarcash');
     317
     318            return;
    265319        }
    266320
    267321        unset($data['card_info']);
     322
     323        $is_recurring = Give_Recurring()->is_donation_recurring($data);
     324
     325        $buyer_id = !empty($data['user_info']['id']) ? $data['user_info']['id'] : null;
     326        $buyer_name = '';
     327        $buyer_email = !empty($data['user_email']) ? $data['user_email'] : '';
     328        $buyer_phone = '';
     329        if (!empty($data['user_info'])) {
     330            if (empty($buyer_email)) {
     331                $buyer_email = $data['user_info']['email'];
     332            }
     333
     334            $buyer_name = $data['user_info']['title'].' '.$data['user_info']['first_name'].' '.$data['user_info']['last_name'];
     335            $buyer_name = trim($buyer_name);
     336        }
     337
     338        $post_data = $data['post_data'];
     339        if (empty($buyer_name)) {
     340            $buyer_name = $post_data['give_title'].' '.$post_data['give_first'].' '.$post_data['give_last'];
     341            $buyer_name = trim($buyer_name);
     342        }
     343
     344        if (empty($buyer_email)) {
     345            $buyer_email = $post_data['give_email'];
     346        }
     347
     348        /*if ($is_recurring) {
     349            if (empty($buyer_id)) {
     350                $subscriber = new Give_Donor($buyer_email);
     351            } else {
     352                $subscriber = new Give_Donor($buyer_id, true);
     353            }
     354
     355            if (empty($subscriber->id)) {
     356                $subscriber->create([
     357                    'name' => trim($buyer_name),
     358                    'email' => $buyer_email,
     359                    'user_id' => $buyer_id,
     360                ]);
     361            }
     362        }*/
     363
     364        $data['user_email'] = $buyer_email;
    268365
    269366        $payment_id = $this->create_payment($data);
     
    275372        }
    276373
     374        // Anonymous
     375        $is_anonymous = isset($data['post_data']['give_anonymous_donation']) && absint($data['post_data']['give_anonymous_donation']);
     376        update_post_meta($payment_id , '_give_anonymous_donation', (int) $is_anonymous);
     377
    277378        $amount = $data['price'];
    278379
    279         $buyer_name = '';
    280         $buyer_email = !empty($data['user_email']) ? $data['user_email'] : '';
    281         $buyer_phone = '';
    282         if (!empty($data['user_info'])) {
    283             if (empty($buyer_email)) {
    284                 $buyer_email = $data['user_info']['email'];
    285             }
    286 
    287             $buyer_name = $data['user_info']['title'].' '.$data['user_info']['first_name'].' '.$data['user_info']['last_name'];
    288             $buyer_name = trim($buyer_name);
    289         }
    290 
    291         $post_data = $data['post_data'];
    292         if (empty($buyer_name)) {
    293             $buyer_name = $post_data['give_title'].' '.$post_data['give_first'].' '.$post_data['give_last'];
    294             $buyer_name = trim($buyer_name);
    295         }
    296 
    297         if (empty($buyer_email)) {
    298             $buyer_email = $post_data['give_email'];
    299         }
    300 
    301         if (isset($purchase_data['give-form-url'])) {
    302             $return_url = $purchase_data['give-form-url'];
     380        if (isset($data['give-form-url'])) {
     381            $return_url = $data['give-form-url'];
    303382        } else {
    304383            $return_url = site_url('/give-api/bayarcash_gateway/');
     
    595674        return false;
    596675    }
     676
     677    public function process_cancellation($data)
     678    {
     679        // Need the sub ID to proceed.
     680        if (empty($data['sub_id'])) {
     681            return;
     682        }
     683
     684        /*
     685         * Sanity check:
     686         *
     687         * a) If subscriber is not logged in.
     688         * b) email access is not enabled nor active.
     689         * c) they don't have an active donation session.
     690         */
     691        if (
     692            !is_user_logged_in()
     693            && false == Give_Recurring()->subscriber_has_email_access()
     694            && !give_get_purchase_session()
     695        ) {
     696            return;
     697        }
     698
     699        // Get subscription id.
     700        $data['sub_id'] = absint($data['sub_id']);
     701
     702        // Verify the nonce for security.
     703        if (!wp_verify_nonce($data['_wpnonce'], "give-recurring-cancel-{$data['sub_id']}")) {
     704            wp_die(__('Nonce verification failed.', 'bayarcash-givewp'), __('Error', 'bayarcash-givewp'), ['response' => 403]);
     705        }
     706
     707        $subscription = new Give_Subscription($data['sub_id']);
     708
     709        if (!$subscription->can_cancel()) {
     710            wp_die(__('This subscription cannot be cancelled.', 'bayarcash-givewp'), __('Error', 'bayarcash-givewp'), ['response' => 403]);
     711        }
     712
     713        try {
     714            do_action('give_recurring_cancel_'.$subscription->gateway.'_subscription', $subscription, true);
     715
     716            $subscription->cancel();
     717
     718            if (is_admin()) {
     719                wp_redirect(admin_url('edit.php?post_type=give_forms&page=give-subscriptions&give-message=cancelled&id='.$subscription->id));
     720                exit;
     721            }
     722
     723            $args = !give_get_errors() ? ['give-message' => 'cancelled'] : [];
     724
     725            wp_redirect(
     726                remove_query_arg(
     727                    [
     728                        '_wpnonce',
     729                        'give_action',
     730                        'sub_id',
     731                    ],
     732                    add_query_arg($args)
     733                )
     734            );
     735
     736            exit;
     737        } catch (Exception $e) {
     738            wp_die($e->getMessage(), __('Error', 'bayarcash-givewp'), ['response' => 403]);
     739        }
     740    }
     741
     742    public function can_cancel($ret, $subscription)
     743    {
     744        return $ret;
     745    }
     746
     747    public function can_sync($ret, $subscription)
     748    {
     749        return $ret;
     750    }
     751
     752    public function can_update($ret, $subscription)
     753    {
     754        return $ret;
     755    }
     756
     757    public function can_update_subscription($ret, $subscription)
     758    {
     759        return $ret;
     760    }
     761
     762    public function update_payment_method($subscriber, $subscription, $data = null)
     763    {
     764    }
     765
     766    public function link_profile_id($profile_id, $subscription)
     767    {
     768        return $profile_id;
     769    }
     770
     771    public function process_payment_method_update($user_id, $subscription_id, $verified)
     772    {
     773        $subscription = new Give_Subscription($subscription_id);
     774
     775        if (empty($subscription->id)) {
     776            give_set_error('give_recurring_invalid_subscription_id', __('Invalid subscription ID.', 'bayarcash-givewp'));
     777        }
     778
     779        if ('bayarcash' !== $subscription->gateway) {
     780            return;
     781        }
     782
     783        if (!$subscription->can_update()) {
     784            give_set_error('give_recurring_subscription_not_updated', __('This subscription cannot be updated.', 'bayarcash-givewp'));
     785        }
     786
     787        $subscriber = new Give_Recurring_Subscriber($subscription->customer_id);
     788        if (empty($subscriber->id)) {
     789            give_set_error('give_recurring_invalid_subscriber', __('Invalid subscriber.', 'bayarcash-givewp'));
     790        }
     791
     792        // Make sure the User doing the update is the user the subscription belongs to
     793        if ($user_id !== $subscriber->id) {
     794            give_set_error('give_recurring_subscriber_not_match', __('User ID and Subscriber do not match.', 'bayarcash-givewp'));
     795        }
     796
     797        do_action('give_recurring_update_bayarcash_subscription', $subscriber, $subscription);
     798
     799        $errors = give_get_errors();
     800
     801        if (!wp_doing_ajax()) {
     802            if (empty($errors)) {
     803                $url = add_query_arg(['action' => 'update', 'updated' => true, 'subscription_id' => $subscription->id], give_get_subscriptions_page_uri());
     804            } else {
     805                $url = add_query_arg(['action' => 'update', 'subscription_id' => $subscription->id], give_get_subscriptions_page_uri());
     806            }
     807
     808            wp_safe_redirect($url);
     809            exit;
     810        }
     811
     812        if (empty($errors)) {
     813            $url = add_query_arg(
     814                [
     815                    'action' => 'update',
     816                    'updated' => '1',
     817                    'status' => 'success',
     818                    'subscription_id' => $subscription->id,
     819                ],
     820                give_get_subscriptions_page_uri()
     821            );
     822
     823            wp_send_json_success(['url' => $url]);
     824        }
     825
     826        $url = add_query_arg(
     827            [
     828                'action' => 'update',
     829                'subscription_id' => $subscription->id,
     830                'status' => 'error',
     831            ],
     832            give_get_subscriptions_page_uri()
     833        );
     834
     835        wp_send_json_error(['url' => $url]);
     836    }
     837
     838    public function process_renewal_subscription_update($user_id, $subscription_id, $verified)
     839    {
     840        $subscription = new Give_Subscription($subscription_id);
     841
     842        // Bail out, if Gateway not match.
     843        if ('bayarcash' !== $subscription->gateway) {
     844            return;
     845        }
     846
     847        // Set error if Subscription ID empty.
     848        if (empty($subscription->id)) {
     849            give_set_error('give_recurring_invalid_subscription_id', __('Invalid subscription ID.', 'bayarcash-givewp'));
     850        }
     851
     852        // Set error if Subscription can not be update.
     853        if (!$subscription->can_update_subscription()) {
     854            give_set_error('give_recurring_renewal_subscription_not_updated', __('This subscription cannot be updated.', 'bayarcash-givewp'));
     855        }
     856
     857        // Get Subscriber.
     858        $subscriber = new Give_Recurring_Subscriber($subscription->customer_id);
     859
     860        // Set error if Invalid subscriber.
     861        if (empty($subscriber->id)) {
     862            give_set_error('give_recurring_invalid_subscriber', __('Invalid subscriber.', 'bayarcash-givewp'));
     863        }
     864
     865        // Make sure the User doing the update is the user the subscription belongs to.
     866        if ($user_id !== $subscriber->id) {
     867            give_set_error('give_recurring_subscriber_not_match', __('User ID and Subscriber do not match.', 'bayarcash-givewp'));
     868        }
     869
     870        $this->validateRenewalAmount($subscription);
     871
     872        /*
     873         * Update renewal subscription information.
     874         * Like renewal amount etc.
     875         *
     876         * @param Give_Recurring_Subscriber  $subscriber
     877         * @param Give_Subscription  $subscription
     878         *
     879         * @since 1.8
     880         *
     881         */
     882        do_action('give_recurring_update_renewal_bayarcash_subscription', $subscriber, $subscription);
     883
     884        // Is errors?
     885        $errors = give_get_errors();
     886
     887        // Build URL based on error got or not.
     888        if (empty($errors)) {
     889            // Update subscription details if don't get any error.
     890            $this->update_renewal_subscription_details($subscription);
     891
     892            $url = add_query_arg(
     893                [
     894                    'action' => 'edit_subscription',
     895                    'subscription_id' => $subscription->id,
     896                    'status' => 'success',
     897                ],
     898                give_get_subscriptions_page_uri()
     899            );
     900
     901            wp_send_json_success(['url' => $url]);
     902        }
     903
     904        $url = add_query_arg(
     905            [
     906                'action' => 'edit_subscription',
     907                'subscription_id' => $subscription->id,
     908                'status' => 'error',
     909            ],
     910            give_get_subscriptions_page_uri()
     911        );
     912
     913        wp_send_json_error(['url' => $url]);
     914    }
    597915}
  • bayarcash-givewp/tags/3.0.0/includes/src/PaymentsQuery.php

    r2920974 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/tags/3.0.0/includes/src/ResponseSanitizer.php

    r2920974 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/tags/3.0.0/includes/src/ResponseValidator.php

    r2920974 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/tags/3.0.0/languages/bayarcash-givewp.pot

    r2920974 r2921565  
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2023-06-01T14:39:58+00:00\n"
     12"POT-Creation-Date: 2023-06-04T17:47:59+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.7.1\n"
     
    2828
    2929#. Author of the plugin
    30 msgid "Web Impian Sdn. Bhd."
     30msgid "Bayarcash"
    3131msgstr ""
    3232
     
    3939msgstr ""
    4040
    41 #: includes/src/Bayarcash.php:134
     41#: includes/src/Bayarcash.php:141
    4242msgid "Bayarcash require GiveWP plugin. Please install and activate."
    4343msgstr ""
    4444
    45 #: includes/src/Givewp.php:39
    46 #: includes/src/Givewp.php:40
    47 #: includes/src/Givewp.php:47
    48 #: includes/src/Givewp.php:152
     45#: includes/src/Givewp.php:44
     46#: includes/src/Givewp.php:45
     47#: includes/src/Givewp.php:52
     48#: includes/src/Givewp.php:157
    4949msgid "Bayarcash"
    5050msgstr ""
    5151
    52 #: includes/src/Givewp.php:66
     52#: includes/src/Givewp.php:71
    5353msgid "General Settings"
    5454msgstr ""
    5555
    56 #: includes/src/Givewp.php:71
    57 #: includes/src/Givewp.php:118
     56#: includes/src/Givewp.php:76
     57#: includes/src/Givewp.php:123
    5858msgid "Bearer Token"
    59 msgstr ""
    60 
    61 #: includes/src/Givewp.php:72
    62 #: includes/src/Givewp.php:119
    63 msgid "Enter your Bearer Token."
    6459msgstr ""
    6560
    6661#: includes/src/Givewp.php:77
    6762#: includes/src/Givewp.php:124
     63msgid "Enter your Bearer Token."
     64msgstr ""
     65
     66#: includes/src/Givewp.php:82
     67#: includes/src/Givewp.php:129
    6868msgid "Bayarcash Portal Key"
    6969msgstr ""
    7070
    71 #: includes/src/Givewp.php:78
    72 #: includes/src/Givewp.php:125
     71#: includes/src/Givewp.php:83
     72#: includes/src/Givewp.php:130
    7373msgid "Enter your portal key."
    7474msgstr ""
    7575
    76 #: includes/src/Givewp.php:87
     76#: includes/src/Givewp.php:92
    7777msgid "Reference Settings"
    7878msgstr ""
    7979
    80 #: includes/src/Givewp.php:92
    81 #: includes/src/Givewp.php:130
     80#: includes/src/Givewp.php:97
     81#: includes/src/Givewp.php:135
    8282msgid "Billing Fields"
    83 msgstr ""
    84 
    85 #: includes/src/Givewp.php:93
    86 #: includes/src/Givewp.php:131
    87 msgid "This option will enable the billing details section at the donation form."
    8883msgstr ""
    8984
    9085#: includes/src/Givewp.php:98
    9186#: includes/src/Givewp.php:136
     87msgid "This option will enable the billing details section at the donation form."
     88msgstr ""
     89
     90#: includes/src/Givewp.php:103
     91#: includes/src/Givewp.php:141
    9292msgid "Enabled"
    9393msgstr ""
    9494
    95 #: includes/src/Givewp.php:99
    96 #: includes/src/Givewp.php:137
     95#: includes/src/Givewp.php:104
     96#: includes/src/Givewp.php:142
    9797msgid "Disabled"
    9898msgstr ""
    9999
    100 #: includes/src/Givewp.php:189
     100#: includes/src/Givewp.php:194
    101101msgid "Make your donation quickly and securely with Bayarcash"
    102102msgstr ""
    103103
    104 #: includes/src/Givewp.php:190
     104#: includes/src/Givewp.php:195
    105105msgid "How it works:"
    106106msgstr ""
    107107
    108 #: includes/src/Givewp.php:191
     108#: includes/src/Givewp.php:196
    109109msgid "You will be redirected to Bayarcash to pay using your online banking. You will then be brought back to this page to view your receipt."
    110110msgstr ""
    111111
     112#: includes/src/Givewp.php:235
     113msgid "Please tick the create account button if you want to create a subscription donation"
     114msgstr ""
     115
    112116#. translators: %s: payment data
    113 #: includes/src/Givewp.php:272
     117#: includes/src/Givewp.php:369
    114118msgid "Payment creation failed before sending donor to Bayarcash. Payment data: %s"
    115119msgstr ""
    116120
    117 #: includes/src/Givewp.php:273
     121#: includes/src/Givewp.php:370
    118122msgid "Payment Error"
    119123msgstr ""
     124
     125#: includes/src/Givewp.php:700
     126msgid "Nonce verification failed."
     127msgstr ""
     128
     129#: includes/src/Givewp.php:700
     130#: includes/src/Givewp.php:706
     131#: includes/src/Givewp.php:734
     132msgid "Error"
     133msgstr ""
     134
     135#: includes/src/Givewp.php:706
     136msgid "This subscription cannot be cancelled."
     137msgstr ""
     138
     139#: includes/src/Givewp.php:772
     140#: includes/src/Givewp.php:845
     141msgid "Invalid subscription ID."
     142msgstr ""
     143
     144#: includes/src/Givewp.php:780
     145#: includes/src/Givewp.php:850
     146msgid "This subscription cannot be updated."
     147msgstr ""
     148
     149#: includes/src/Givewp.php:785
     150#: includes/src/Givewp.php:858
     151msgid "Invalid subscriber."
     152msgstr ""
     153
     154#: includes/src/Givewp.php:790
     155#: includes/src/Givewp.php:863
     156msgid "User ID and Subscriber do not match."
     157msgstr ""
  • bayarcash-givewp/trunk/bayarcash-givewp.php

    r2920975 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
     
    1515 * Version:             3.0.0
    1616 * Description:         Bayarcash payment plugin for GiveWP
    17  * Author:              Web Impian Sdn. Bhd.
     17 * Author:              Bayarcash
    1818 * Author URI:          https://bayarcash.com/?utm_source=wp-plugins-givewps&utm_campaign=author-uri&utm_medium=wp-dash
    1919 * Requires at least:   5.6
  • bayarcash-givewp/trunk/includes/src/Bayarcash.php

    r2920975 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
     
    121121            }
    122122        });
     123
     124        // Must define before give_recurring is loaded.
     125        add_filter('give_recurring_available_gateways', function ($gateways) {
     126            $gateways['bayarcash'] = 'BayarCash\\GiveWP\\Givewp';
     127
     128            return $gateways;
     129        });
    123130    }
    124131
  • bayarcash-givewp/trunk/includes/src/FpxApi.php

    r2920975 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/trunk/includes/src/FpxCron.php

    r2920975 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/trunk/includes/src/FpxDatabase.php

    r2920975 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/trunk/includes/src/FpxResponseTransformer.php

    r2920975 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/trunk/includes/src/FpxTransactionStatus.php

    r2920975 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/trunk/includes/src/Givewp.php

    r2920975 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
     
    1313\defined('ABSPATH') || exit;
    1414
     15use Exception;
    1516use Give\Helpers\Form\Utils as FormUtils;
     17use Give_Donor;
     18use Give_Recurring_Subscriber;
     19use Give_Subscription;
    1620
    1721final class Givewp
     
    3034        $this->form_setups();
    3135        $this->payment_setups();
     36        $this->subscription_setups();
    3237        $this->pt->register_cronjob();
    3338    }
     
    213218    }
    214219
     220    private function subscription_setups()
     221    {
     222        add_action('give_checkout_error_checks', function ($valid_data) {
     223            $post_data = give_clean($_POST);
     224            if (!empty($post_data['give-gateway']) && 'bayarcash' !== $post_data['give-gateway']) {
     225                return;
     226            }
     227
     228            if (!is_user_logged_in() && !empty($post_data['give-form-id'])) {
     229                $form_id = absint($post_data['give-form-id']);
     230
     231                // Only required if email access not on & recurring enabled.
     232                if (give_is_form_recurring($form_id) && !give_is_setting_enabled(give_get_option('email_access'))) {
     233                    // check if form is recurring and create account checkbox should be checked.
     234                    if (!empty($post_data['_give_is_donation_recurring']) && empty($post_data['give_create_account'])) {
     235                        give_set_error('recurring_create_account', __('Please tick the create account button if you want to create a subscription donation', 'bayarcash-givewp'));
     236                    }
     237                }
     238            }
     239        }, 0, 1);
     240
     241        add_action('give_cancel_subscription', [$this, 'process_cancellation']);
     242        add_filter('give_subscription_can_cancel', [$this, 'can_cancel'], 10, 2);
     243        add_filter('give_subscription_can_sync', [$this, 'can_sync'], 10, 2);
     244        add_filter('give_subscription_can_update', [$this, 'can_update'], 10, 2);
     245        add_filter('give_subscription_can_update_subscription', [$this, 'can_update_subscription'], 10, 2);
     246
     247        add_filter('give_subscription_can_cancel_bayarcash_subscription', [
     248            $this,
     249            'can_cancel',
     250        ], 10, 2);
     251
     252        add_action('give_recurring_update_subscription_payment_method', [
     253            $this,
     254            'process_payment_method_update',
     255        ], 10, 3);
     256
     257        add_filter('give_subscription_profile_link_bayarcash', [$this, 'link_profile_id'], 10, 2);
     258        add_action('give_recurring_update_bayarcash_subscription', [$this, 'update_payment_method'], 10, 2);
     259
     260        add_action('give_recurring_update_renewal_subscription', [
     261            $this,
     262            'process_renewal_subscription_update',
     263        ], 10, 3);
     264        add_action('give_recurring_update_renewal_bayarcash_subscription', [$this, 'update_subscription'], 10, 2);
     265    }
     266
    215267    private function endpoint_tokens($form_id)
    216268    {
     
    263315        if (give_get_errors()) {
    264316            give_send_back_to_checkout('?payment-mode=bayarcash');
     317
     318            return;
    265319        }
    266320
    267321        unset($data['card_info']);
     322
     323        $is_recurring = Give_Recurring()->is_donation_recurring($data);
     324
     325        $buyer_id = !empty($data['user_info']['id']) ? $data['user_info']['id'] : null;
     326        $buyer_name = '';
     327        $buyer_email = !empty($data['user_email']) ? $data['user_email'] : '';
     328        $buyer_phone = '';
     329        if (!empty($data['user_info'])) {
     330            if (empty($buyer_email)) {
     331                $buyer_email = $data['user_info']['email'];
     332            }
     333
     334            $buyer_name = $data['user_info']['title'].' '.$data['user_info']['first_name'].' '.$data['user_info']['last_name'];
     335            $buyer_name = trim($buyer_name);
     336        }
     337
     338        $post_data = $data['post_data'];
     339        if (empty($buyer_name)) {
     340            $buyer_name = $post_data['give_title'].' '.$post_data['give_first'].' '.$post_data['give_last'];
     341            $buyer_name = trim($buyer_name);
     342        }
     343
     344        if (empty($buyer_email)) {
     345            $buyer_email = $post_data['give_email'];
     346        }
     347
     348        /*if ($is_recurring) {
     349            if (empty($buyer_id)) {
     350                $subscriber = new Give_Donor($buyer_email);
     351            } else {
     352                $subscriber = new Give_Donor($buyer_id, true);
     353            }
     354
     355            if (empty($subscriber->id)) {
     356                $subscriber->create([
     357                    'name' => trim($buyer_name),
     358                    'email' => $buyer_email,
     359                    'user_id' => $buyer_id,
     360                ]);
     361            }
     362        }*/
     363
     364        $data['user_email'] = $buyer_email;
    268365
    269366        $payment_id = $this->create_payment($data);
     
    275372        }
    276373
     374        // Anonymous
     375        $is_anonymous = isset($data['post_data']['give_anonymous_donation']) && absint($data['post_data']['give_anonymous_donation']);
     376        update_post_meta($payment_id , '_give_anonymous_donation', (int) $is_anonymous);
     377
    277378        $amount = $data['price'];
    278379
    279         $buyer_name = '';
    280         $buyer_email = !empty($data['user_email']) ? $data['user_email'] : '';
    281         $buyer_phone = '';
    282         if (!empty($data['user_info'])) {
    283             if (empty($buyer_email)) {
    284                 $buyer_email = $data['user_info']['email'];
    285             }
    286 
    287             $buyer_name = $data['user_info']['title'].' '.$data['user_info']['first_name'].' '.$data['user_info']['last_name'];
    288             $buyer_name = trim($buyer_name);
    289         }
    290 
    291         $post_data = $data['post_data'];
    292         if (empty($buyer_name)) {
    293             $buyer_name = $post_data['give_title'].' '.$post_data['give_first'].' '.$post_data['give_last'];
    294             $buyer_name = trim($buyer_name);
    295         }
    296 
    297         if (empty($buyer_email)) {
    298             $buyer_email = $post_data['give_email'];
    299         }
    300 
    301         if (isset($purchase_data['give-form-url'])) {
    302             $return_url = $purchase_data['give-form-url'];
     380        if (isset($data['give-form-url'])) {
     381            $return_url = $data['give-form-url'];
    303382        } else {
    304383            $return_url = site_url('/give-api/bayarcash_gateway/');
     
    595674        return false;
    596675    }
     676
     677    public function process_cancellation($data)
     678    {
     679        // Need the sub ID to proceed.
     680        if (empty($data['sub_id'])) {
     681            return;
     682        }
     683
     684        /*
     685         * Sanity check:
     686         *
     687         * a) If subscriber is not logged in.
     688         * b) email access is not enabled nor active.
     689         * c) they don't have an active donation session.
     690         */
     691        if (
     692            !is_user_logged_in()
     693            && false == Give_Recurring()->subscriber_has_email_access()
     694            && !give_get_purchase_session()
     695        ) {
     696            return;
     697        }
     698
     699        // Get subscription id.
     700        $data['sub_id'] = absint($data['sub_id']);
     701
     702        // Verify the nonce for security.
     703        if (!wp_verify_nonce($data['_wpnonce'], "give-recurring-cancel-{$data['sub_id']}")) {
     704            wp_die(__('Nonce verification failed.', 'bayarcash-givewp'), __('Error', 'bayarcash-givewp'), ['response' => 403]);
     705        }
     706
     707        $subscription = new Give_Subscription($data['sub_id']);
     708
     709        if (!$subscription->can_cancel()) {
     710            wp_die(__('This subscription cannot be cancelled.', 'bayarcash-givewp'), __('Error', 'bayarcash-givewp'), ['response' => 403]);
     711        }
     712
     713        try {
     714            do_action('give_recurring_cancel_'.$subscription->gateway.'_subscription', $subscription, true);
     715
     716            $subscription->cancel();
     717
     718            if (is_admin()) {
     719                wp_redirect(admin_url('edit.php?post_type=give_forms&page=give-subscriptions&give-message=cancelled&id='.$subscription->id));
     720                exit;
     721            }
     722
     723            $args = !give_get_errors() ? ['give-message' => 'cancelled'] : [];
     724
     725            wp_redirect(
     726                remove_query_arg(
     727                    [
     728                        '_wpnonce',
     729                        'give_action',
     730                        'sub_id',
     731                    ],
     732                    add_query_arg($args)
     733                )
     734            );
     735
     736            exit;
     737        } catch (Exception $e) {
     738            wp_die($e->getMessage(), __('Error', 'bayarcash-givewp'), ['response' => 403]);
     739        }
     740    }
     741
     742    public function can_cancel($ret, $subscription)
     743    {
     744        return $ret;
     745    }
     746
     747    public function can_sync($ret, $subscription)
     748    {
     749        return $ret;
     750    }
     751
     752    public function can_update($ret, $subscription)
     753    {
     754        return $ret;
     755    }
     756
     757    public function can_update_subscription($ret, $subscription)
     758    {
     759        return $ret;
     760    }
     761
     762    public function update_payment_method($subscriber, $subscription, $data = null)
     763    {
     764    }
     765
     766    public function link_profile_id($profile_id, $subscription)
     767    {
     768        return $profile_id;
     769    }
     770
     771    public function process_payment_method_update($user_id, $subscription_id, $verified)
     772    {
     773        $subscription = new Give_Subscription($subscription_id);
     774
     775        if (empty($subscription->id)) {
     776            give_set_error('give_recurring_invalid_subscription_id', __('Invalid subscription ID.', 'bayarcash-givewp'));
     777        }
     778
     779        if ('bayarcash' !== $subscription->gateway) {
     780            return;
     781        }
     782
     783        if (!$subscription->can_update()) {
     784            give_set_error('give_recurring_subscription_not_updated', __('This subscription cannot be updated.', 'bayarcash-givewp'));
     785        }
     786
     787        $subscriber = new Give_Recurring_Subscriber($subscription->customer_id);
     788        if (empty($subscriber->id)) {
     789            give_set_error('give_recurring_invalid_subscriber', __('Invalid subscriber.', 'bayarcash-givewp'));
     790        }
     791
     792        // Make sure the User doing the update is the user the subscription belongs to
     793        if ($user_id !== $subscriber->id) {
     794            give_set_error('give_recurring_subscriber_not_match', __('User ID and Subscriber do not match.', 'bayarcash-givewp'));
     795        }
     796
     797        do_action('give_recurring_update_bayarcash_subscription', $subscriber, $subscription);
     798
     799        $errors = give_get_errors();
     800
     801        if (!wp_doing_ajax()) {
     802            if (empty($errors)) {
     803                $url = add_query_arg(['action' => 'update', 'updated' => true, 'subscription_id' => $subscription->id], give_get_subscriptions_page_uri());
     804            } else {
     805                $url = add_query_arg(['action' => 'update', 'subscription_id' => $subscription->id], give_get_subscriptions_page_uri());
     806            }
     807
     808            wp_safe_redirect($url);
     809            exit;
     810        }
     811
     812        if (empty($errors)) {
     813            $url = add_query_arg(
     814                [
     815                    'action' => 'update',
     816                    'updated' => '1',
     817                    'status' => 'success',
     818                    'subscription_id' => $subscription->id,
     819                ],
     820                give_get_subscriptions_page_uri()
     821            );
     822
     823            wp_send_json_success(['url' => $url]);
     824        }
     825
     826        $url = add_query_arg(
     827            [
     828                'action' => 'update',
     829                'subscription_id' => $subscription->id,
     830                'status' => 'error',
     831            ],
     832            give_get_subscriptions_page_uri()
     833        );
     834
     835        wp_send_json_error(['url' => $url]);
     836    }
     837
     838    public function process_renewal_subscription_update($user_id, $subscription_id, $verified)
     839    {
     840        $subscription = new Give_Subscription($subscription_id);
     841
     842        // Bail out, if Gateway not match.
     843        if ('bayarcash' !== $subscription->gateway) {
     844            return;
     845        }
     846
     847        // Set error if Subscription ID empty.
     848        if (empty($subscription->id)) {
     849            give_set_error('give_recurring_invalid_subscription_id', __('Invalid subscription ID.', 'bayarcash-givewp'));
     850        }
     851
     852        // Set error if Subscription can not be update.
     853        if (!$subscription->can_update_subscription()) {
     854            give_set_error('give_recurring_renewal_subscription_not_updated', __('This subscription cannot be updated.', 'bayarcash-givewp'));
     855        }
     856
     857        // Get Subscriber.
     858        $subscriber = new Give_Recurring_Subscriber($subscription->customer_id);
     859
     860        // Set error if Invalid subscriber.
     861        if (empty($subscriber->id)) {
     862            give_set_error('give_recurring_invalid_subscriber', __('Invalid subscriber.', 'bayarcash-givewp'));
     863        }
     864
     865        // Make sure the User doing the update is the user the subscription belongs to.
     866        if ($user_id !== $subscriber->id) {
     867            give_set_error('give_recurring_subscriber_not_match', __('User ID and Subscriber do not match.', 'bayarcash-givewp'));
     868        }
     869
     870        $this->validateRenewalAmount($subscription);
     871
     872        /*
     873         * Update renewal subscription information.
     874         * Like renewal amount etc.
     875         *
     876         * @param Give_Recurring_Subscriber  $subscriber
     877         * @param Give_Subscription  $subscription
     878         *
     879         * @since 1.8
     880         *
     881         */
     882        do_action('give_recurring_update_renewal_bayarcash_subscription', $subscriber, $subscription);
     883
     884        // Is errors?
     885        $errors = give_get_errors();
     886
     887        // Build URL based on error got or not.
     888        if (empty($errors)) {
     889            // Update subscription details if don't get any error.
     890            $this->update_renewal_subscription_details($subscription);
     891
     892            $url = add_query_arg(
     893                [
     894                    'action' => 'edit_subscription',
     895                    'subscription_id' => $subscription->id,
     896                    'status' => 'success',
     897                ],
     898                give_get_subscriptions_page_uri()
     899            );
     900
     901            wp_send_json_success(['url' => $url]);
     902        }
     903
     904        $url = add_query_arg(
     905            [
     906                'action' => 'edit_subscription',
     907                'subscription_id' => $subscription->id,
     908                'status' => 'error',
     909            ],
     910            give_get_subscriptions_page_uri()
     911        );
     912
     913        wp_send_json_error(['url' => $url]);
     914    }
    597915}
  • bayarcash-givewp/trunk/includes/src/PaymentsQuery.php

    r2920975 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/trunk/includes/src/ResponseSanitizer.php

    r2920975 r2921565  
    33 * Bayarcash GiveWP.
    44 *
    5  * @author  Web Impian Sdn. Bhd.
     5 * @author  Bayarcash
    66 * @license GPLv3
    77 *
  • bayarcash-givewp/trunk/includes/vendor/composer

    • Property svn:ignore set to
      ClassLoader.php-e
  • bayarcash-givewp/trunk/languages/bayarcash-givewp.pot

    r2920976 r2921565  
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2023-06-01T14:39:58+00:00\n"
     12"POT-Creation-Date: 2023-06-04T17:47:59+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.7.1\n"
     
    2828
    2929#. Author of the plugin
    30 msgid "Web Impian Sdn. Bhd."
     30msgid "Bayarcash"
    3131msgstr ""
    3232
     
    3939msgstr ""
    4040
    41 #: includes/src/Bayarcash.php:134
     41#: includes/src/Bayarcash.php:141
    4242msgid "Bayarcash require GiveWP plugin. Please install and activate."
    4343msgstr ""
    4444
    45 #: includes/src/Givewp.php:39
    46 #: includes/src/Givewp.php:40
    47 #: includes/src/Givewp.php:47
    48 #: includes/src/Givewp.php:152
     45#: includes/src/Givewp.php:44
     46#: includes/src/Givewp.php:45
     47#: includes/src/Givewp.php:52
     48#: includes/src/Givewp.php:157
    4949msgid "Bayarcash"
    5050msgstr ""
    5151
    52 #: includes/src/Givewp.php:66
     52#: includes/src/Givewp.php:71
    5353msgid "General Settings"
    5454msgstr ""
    5555
    56 #: includes/src/Givewp.php:71
    57 #: includes/src/Givewp.php:118
     56#: includes/src/Givewp.php:76
     57#: includes/src/Givewp.php:123
    5858msgid "Bearer Token"
    59 msgstr ""
    60 
    61 #: includes/src/Givewp.php:72
    62 #: includes/src/Givewp.php:119
    63 msgid "Enter your Bearer Token."
    6459msgstr ""
    6560
    6661#: includes/src/Givewp.php:77
    6762#: includes/src/Givewp.php:124
     63msgid "Enter your Bearer Token."
     64msgstr ""
     65
     66#: includes/src/Givewp.php:82
     67#: includes/src/Givewp.php:129
    6868msgid "Bayarcash Portal Key"
    6969msgstr ""
    7070
    71 #: includes/src/Givewp.php:78
    72 #: includes/src/Givewp.php:125
     71#: includes/src/Givewp.php:83
     72#: includes/src/Givewp.php:130
    7373msgid "Enter your portal key."
    7474msgstr ""
    7575
    76 #: includes/src/Givewp.php:87
     76#: includes/src/Givewp.php:92
    7777msgid "Reference Settings"
    7878msgstr ""
    7979
    80 #: includes/src/Givewp.php:92
    81 #: includes/src/Givewp.php:130
     80#: includes/src/Givewp.php:97
     81#: includes/src/Givewp.php:135
    8282msgid "Billing Fields"
    83 msgstr ""
    84 
    85 #: includes/src/Givewp.php:93
    86 #: includes/src/Givewp.php:131
    87 msgid "This option will enable the billing details section at the donation form."
    8883msgstr ""
    8984
    9085#: includes/src/Givewp.php:98
    9186#: includes/src/Givewp.php:136
     87msgid "This option will enable the billing details section at the donation form."
     88msgstr ""
     89
     90#: includes/src/Givewp.php:103
     91#: includes/src/Givewp.php:141
    9292msgid "Enabled"
    9393msgstr ""
    9494
    95 #: includes/src/Givewp.php:99
    96 #: includes/src/Givewp.php:137
     95#: includes/src/Givewp.php:104
     96#: includes/src/Givewp.php:142
    9797msgid "Disabled"
    9898msgstr ""
    9999
    100 #: includes/src/Givewp.php:189
     100#: includes/src/Givewp.php:194
    101101msgid "Make your donation quickly and securely with Bayarcash"
    102102msgstr ""
    103103
    104 #: includes/src/Givewp.php:190
     104#: includes/src/Givewp.php:195
    105105msgid "How it works:"
    106106msgstr ""
    107107
    108 #: includes/src/Givewp.php:191
     108#: includes/src/Givewp.php:196
    109109msgid "You will be redirected to Bayarcash to pay using your online banking. You will then be brought back to this page to view your receipt."
    110110msgstr ""
    111111
     112#: includes/src/Givewp.php:235
     113msgid "Please tick the create account button if you want to create a subscription donation"
     114msgstr ""
     115
    112116#. translators: %s: payment data
    113 #: includes/src/Givewp.php:272
     117#: includes/src/Givewp.php:369
    114118msgid "Payment creation failed before sending donor to Bayarcash. Payment data: %s"
    115119msgstr ""
    116120
    117 #: includes/src/Givewp.php:273
     121#: includes/src/Givewp.php:370
    118122msgid "Payment Error"
    119123msgstr ""
     124
     125#: includes/src/Givewp.php:700
     126msgid "Nonce verification failed."
     127msgstr ""
     128
     129#: includes/src/Givewp.php:700
     130#: includes/src/Givewp.php:706
     131#: includes/src/Givewp.php:734
     132msgid "Error"
     133msgstr ""
     134
     135#: includes/src/Givewp.php:706
     136msgid "This subscription cannot be cancelled."
     137msgstr ""
     138
     139#: includes/src/Givewp.php:772
     140#: includes/src/Givewp.php:845
     141msgid "Invalid subscription ID."
     142msgstr ""
     143
     144#: includes/src/Givewp.php:780
     145#: includes/src/Givewp.php:850
     146msgid "This subscription cannot be updated."
     147msgstr ""
     148
     149#: includes/src/Givewp.php:785
     150#: includes/src/Givewp.php:858
     151msgid "Invalid subscriber."
     152msgstr ""
     153
     154#: includes/src/Givewp.php:790
     155#: includes/src/Givewp.php:863
     156msgid "User ID and Subscriber do not match."
     157msgstr ""
Note: See TracChangeset for help on using the changeset viewer.