| 1 |
<?php |
| 2 |
|
| 3 |
namespace SureCart\Integrations; |
| 4 |
|
| 5 |
/** |
| 6 |
* Abstract integrations class. |
| 7 |
*/ |
| 8 |
abstract class AbstractIntegration { |
| 9 |
/** |
| 10 |
* Run an action when a purchase is created |
| 11 |
* |
| 12 |
* @param \SureCart\Models\Integration $integration The integrations. |
| 13 |
* @param \WP_User $wp_user The user. |
| 14 |
* |
| 15 |
* @return boolean|void Returns true if the user course access updation was successful otherwise false. |
| 16 |
*/ |
| 17 |
public function onPurchaseCreated( $integration, $wp_user ) { |
| 18 |
return new \WP_Error( |
| 19 |
'invalid-method', |
| 20 |
/* translators: %s: Method name. */ |
| 21 |
sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'surecart' ), __METHOD__ ), |
| 22 |
array( 'status' => 405 ) |
| 23 |
); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Run an action when a purchase is revoked. |
| 28 |
* |
| 29 |
* @param \SureCart\Models\Integration $integration The integrations. |
| 30 |
* @param \WP_User $wp_user The user. |
| 31 |
* |
| 32 |
* @return boolean|void Returns true if the user course access updation was successful otherwise false. |
| 33 |
*/ |
| 34 |
public function onPurchaseRevoked( $integration, $wp_user ) { |
| 35 |
return new \WP_Error( |
| 36 |
'invalid-method', |
| 37 |
/* translators: %s: Method name. */ |
| 38 |
sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'surecart' ), __METHOD__ ), |
| 39 |
array( 'status' => 405 ) |
| 40 |
); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Run an action when a purchase is invoked. |
| 45 |
* |
| 46 |
* @param \SureCart\Models\Integration $integration The integrations. |
| 47 |
* @param \WP_User $wp_user The user. |
| 48 |
* |
| 49 |
* @return boolean|void Returns true if the user course access updation was successful otherwise false. |
| 50 |
*/ |
| 51 |
public function onPurchaseInvoked( $integration, $wp_user ) { |
| 52 |
return new \WP_Error( |
| 53 |
'invalid-method', |
| 54 |
/* translators: %s: Method name. */ |
| 55 |
sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'surecart' ), __METHOD__ ), |
| 56 |
array( 'status' => 405 ) |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Method to run when the quantity updates. |
| 62 |
* |
| 63 |
* @param integer $quantity The new quantity. |
| 64 |
* @param integer $previous The previous quantity. |
| 65 |
* @param Purchase $purchase The purchase. |
| 66 |
* @param array $request The request. |
| 67 |
* |
| 68 |
* @return void |
| 69 |
*/ |
| 70 |
public function onPurchaseQuantityUpdated( $quantity, $previous, $purchase, $request ) { |
| 71 |
// do nothing as this is not required. |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Method to run when the purchase product is updated. |
| 76 |
* |
| 77 |
* @param Purchase $quantity The current purchase. |
| 78 |
* @param Purchase $previous_purchase The previous purchase. |
| 79 |
* @param array $request The request. |
| 80 |
* |
| 81 |
* @return void|\WP_Error |
| 82 |
*/ |
| 83 |
public function onPurchaseProductUpdated( \SureCart\Models\Purchase $purchase, \SureCart\Models\Purchase $previous_purchase, $request ) { |
| 84 |
return new \WP_Error( |
| 85 |
'invalid-method', |
| 86 |
/* translators: %s: Method name. */ |
| 87 |
sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'surecart' ), __METHOD__ ), |
| 88 |
array( 'status' => 405 ) |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* The product was added. |
| 94 |
* |
| 95 |
* @param \SureCart\Models\Integration $integration The integrations. |
| 96 |
* @param \WP_User $wp_user The user. |
| 97 |
* |
| 98 |
* @return void |
| 99 |
*/ |
| 100 |
public function onPurchaseProductAdded( $integration, $wp_user ) { |
| 101 |
$this->onPurchaseCreated( $integration, $wp_user ); |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Removed |
| 106 |
* |
| 107 |
* @param \SureCart\Models\Integration $integration The integrations. |
| 108 |
* @param \WP_User $wp_user The user. |
| 109 |
* |
| 110 |
* @return void |
| 111 |
*/ |
| 112 |
public function onPurchaseProductRemoved( $integration, $wp_user ) { |
| 113 |
$this->onPurchaseRevoked( $integration, $wp_user ); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Method to run when a purchase is updated. |
| 118 |
* This can occur if the product or quantity changes. |
| 119 |
* |
| 120 |
* @param Purchase $purchase The purchase. |
| 121 |
* @param array $request The request. |
| 122 |
* |
| 123 |
* @return void |
| 124 |
*/ |
| 125 |
public function onPurchaseUpdated( \SureCart\Models\Purchase $purchase, $request ) { |
| 126 |
// do nothing as this is not required. |
| 127 |
} |
| 128 |
} |
| 129 |
|