A small refactor was performed. check_if_coupon_was_redeemed was moved to AdCredits where it should be.
API error codes have beed added as constants to the error class.
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.
redeem_credits method now correctly catches error codes.
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.
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:
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.
Trigger hourly action to start the coupon redeme process. redeeme attempt should be visible in logs and it should fail.
Check options for billing status - it should be switched to false.
Trigger hourly action again - this time redeem attempt should not happen.
Changes proposed in this Pull Request:
Closes #991 Closes #990
check_if_coupon_was_redeemed
was moved toAdCredits
where it should be.redeem_credits
method now correctly catches error codes.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.Detailed test instructions:
On a setup with no valid billing setup, and no previously redeemed credit:
Pinterest_For_Woocommerce()::add_billing_setup_status_to_account_data( true )
this will make the plugin believe that the billing setup is OK.