| @@ -44,14 +44,23 @@ | ||
| 44 | 44 | self::TRANSACTION_TYPE_DIRECT_CAPTURE, |
| 45 | 45 | self::TRANSACTION_TYPE_RESERVE_CAPTURE, |
| 46 | 46 | ]; |
| 47 | 47 | |
| 48 | + public const PROCESSING_MODE_MULTIPLE_ATTEMPTS = "MULTIPLE_ATTEMPTS"; | |
| 49 | + public const PROCESSING_MODE_SINGLE_ATTEMPT = "SINGLE_ATTEMPT"; | |
| 50 | + | |
| 51 | + protected array $valid_processing_modes = [ | |
| 52 | + self::PROCESSING_MODE_MULTIPLE_ATTEMPTS, | |
| 53 | + self::PROCESSING_MODE_SINGLE_ATTEMPT, | |
| 54 | + ]; | |
| 55 | + | |
| 48 | 56 | protected array $required_fields = [ |
| 49 | 57 | "amount", |
| 50 | 58 | "order_id", |
| 51 | 59 | "description", |
| 52 | 60 | "due", |
| 53 | - "retry_days" | |
| 61 | + "retry_days", | |
| 62 | + "processing_mode", | |
| 54 | 63 | ]; |
| 55 | 64 | |
| 56 | 65 | public ?string $id = null; |
| 57 | 66 | public ?string $order_id = null; |
| @@ -62,8 +71,9 @@ | ||
| 62 | 71 | public ?string $transaction_type = null; |
| 63 | 72 | public ?string $description = null; |
| 64 | 73 | public ?string $currency = null; |
| 65 | 74 | public ?string $external_id = null; |
| 75 | + public ?string $processing_mode = self::PROCESSING_MODE_MULTIPLE_ATTEMPTS; | |
| 66 | 76 | |
| 67 | 77 | /** |
| 68 | 78 | * @var DateTime|string $due |
| 69 | 79 | */ |
| @@ -133,8 +143,22 @@ | ||
| 133 | 143 | |
| 134 | 144 | return $this; |
| 135 | 145 | } |
| 136 | 146 | |
| 147 | + /** | |
| 148 | + * @throws WC_Vipps_Recurring_Invalid_Value_Exception | |
| 149 | + */ | |
| 150 | + public function set_processing_mode( string $processing_mode ): self { | |
| 151 | + if ( ! in_array( $processing_mode, $this->valid_processing_modes, true ) ) { | |
| 152 | + $class = get_class( $this ); | |
| 153 | + throw new WC_Vipps_Recurring_Invalid_Value_Exception( "$processing_mode is not a valid value for `processing_mode` in $class." ); | |
| 154 | + } | |
| 155 | + | |
| 156 | + $this->processing_mode = $processing_mode; | |
| 157 | + | |
| 158 | + return $this; | |
| 159 | + } | |
| 160 | + | |
| 137 | 161 | public function set_transaction_id( string $transaction_id ): self { |
| 138 | 162 | $this->transaction_id = $transaction_id; |
| 139 | 163 | |
| 140 | 164 | return $this; |
| @@ -187,13 +211,14 @@ | ||
| 187 | 211 | } |
| 188 | 212 | |
| 189 | 213 | return array_merge( |
| 190 | 214 | [ |
| 191 | - "orderId" => $this->order_id, | |
| 192 | - "amount" => $this->amount, | |
| 193 | - "description" => $this->description, | |
| 194 | - "due" => $this->serialize_value( $this->due, 'Y-m-d' ), | |
| 195 | - "retryDays" => $this->retry_days | |
| 215 | + "orderId" => $this->order_id, | |
| 216 | + "amount" => $this->amount, | |
| 217 | + "description" => $this->description, | |
| 218 | + "due" => $this->serialize_value( $this->due, 'Y-m-d' ), | |
| 219 | + "retryDays" => $this->retry_days, | |
| 220 | + "processingMode" => $this->processing_mode, | |
| 196 | 221 | ], |
| 197 | 222 | $this->conditional( "type", $this->type ), |
| 198 | 223 | $this->conditional( "transactionType", $this->transaction_type ), |
| 199 | 224 | $this->conditional( "transactionId", $this->transaction_id ), |