PurchaseCreatedTrigger.php
3 years ago
PurchaseInvokedTrigger.php
3 years ago
PurchaseRevokedTrigger.php
3 years ago
PurchaseUpdatedTrigger.php
3 years ago
PurchaseInvokedTrigger.php
109 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Integrations\ThriveAutomator\Triggers; |
| 4 | |
| 5 | use SureCart\Integrations\ThriveAutomator\DataObjects\ProductDataObject; |
| 6 | use SureCart\Integrations\ThriveAutomator\ThriveAutomatorApp; |
| 7 | use SureCart\Models\User; |
| 8 | use Thrive\Automator\Items\Data_Object; |
| 9 | use Thrive\Automator\Items\Trigger; |
| 10 | |
| 11 | /** |
| 12 | * Handles the purchase revoked event. |
| 13 | */ |
| 14 | class PurchaseInvokedTrigger extends Trigger { |
| 15 | /** |
| 16 | * Get the trigger identifier |
| 17 | * |
| 18 | * @return string |
| 19 | */ |
| 20 | public static function get_id() { |
| 21 | return 'surecart_purchase_invoked'; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Get the trigger hook |
| 26 | * |
| 27 | * @return string |
| 28 | */ |
| 29 | public static function get_wp_hook() { |
| 30 | return 'surecart/purchase_invoked'; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Get the app id. |
| 35 | * |
| 36 | * @return string |
| 37 | */ |
| 38 | public static function get_app_id() { |
| 39 | return ThriveAutomatorApp::get_id(); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get the trigger provided params |
| 44 | * |
| 45 | * @return array |
| 46 | */ |
| 47 | public static function get_provided_data_objects() { |
| 48 | return [ ProductDataObject::get_id(), 'user_data' ]; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Get the number of params |
| 53 | * |
| 54 | * @return int |
| 55 | */ |
| 56 | public static function get_hook_params_number() { |
| 57 | return 1; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Get the trigger name |
| 62 | * |
| 63 | * @return string |
| 64 | */ |
| 65 | public static function get_name() { |
| 66 | return __( 'Admin unrevokes a purchase', 'surecart' ); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Get the trigger description |
| 71 | * |
| 72 | * @return string |
| 73 | */ |
| 74 | public static function get_description() { |
| 75 | return __( 'This trigger will be fired when a purchase is unrevoked.', 'surecart' ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get the trigger logo |
| 80 | * |
| 81 | * @return string |
| 82 | */ |
| 83 | public static function get_image() { |
| 84 | return esc_url( trailingslashit( plugin_dir_url( SURECART_PLUGIN_FILE ) ) . 'app/src/Integrations/ThriveAutomator/images/icon-color.svg' ); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Process params for action. |
| 89 | * |
| 90 | * @param array $params Params from the action. |
| 91 | * @return array |
| 92 | */ |
| 93 | public function process_params( $params = [] ) { |
| 94 | $data_objects = []; |
| 95 | |
| 96 | if ( ! empty( $params ) ) { |
| 97 | $data_object_classes = Data_Object::get(); |
| 98 | $product_id = $params[0]['product']; |
| 99 | $user = User::findByCustomerId( $params[0]['customer'] ); |
| 100 | |
| 101 | $data_objects['surecart_product_data'] = empty( $data_object_classes['surecart_product_data'] ) ? null : new $data_object_classes['surecart_product_data']( $product_id ); |
| 102 | $data_objects['user_data'] = empty( $data_object_classes['user_data'] ) ? null : new $data_object_classes['user_data']( $user->ID ); |
| 103 | } |
| 104 | |
| 105 | return $data_objects; |
| 106 | } |
| 107 | |
| 108 | } |
| 109 |