woocommerce / pinterest-for-woocommerce

A native Pinterest integration for WooCommerce. Development is managed by Ventures.
https://woocommerce.com/products/pinterest-for-woocommerce/
GNU General Public License v3.0
22 stars 9 forks source link

Update/error cases handling for discounts #995

Closed budzanowski closed 5 months ago

budzanowski commented 5 months ago

Changes proposed in this Pull Request:

Closes #991 Closes #990

  1. A small refactor was performed. check_if_coupon_was_redeemed was moved to AdCredits where it should be.
  2. API error codes have beed added as constants to the error class.
  3. add_billing_setup_info_to_account_data has been split into two separate methods that allows setting the billing status separately from fetching it from API.
  4. redeem_credits method now correctly catches error codes.
  5. If redeem_credits encounters billing setup error it invalidates the billing setup information which will block coupon redemption attempts until the daily action detects that the billing setup was fixed.
  6. Detection of already redeemed coupon by another advertiser has been added.

Detailed test instructions:

On a setup with no valid billing setup, and no previously redeemed credit:

  1. Mock the billing setup stored value to true. One can trigger manually Pinterest_For_Woocommerce()::add_billing_setup_status_to_account_data( true ) this will make the plugin believe that the billing setup is OK.
  2. Trigger hourly action to start the coupon redeme process. redeeme attempt should be visible in logs and it should fail.
  3. Check options for billing status - it should be switched to false.
  4. Trigger hourly action again - this time redeem attempt should not happen.