| Total Complexity | 60 |
| Total Lines | 953 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Payment often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Payment, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class Payment { |
||
| 28 | /** |
||
| 29 | * The payment post object. |
||
| 30 | * |
||
| 31 | * @var WP_Post|array |
||
| 32 | */ |
||
| 33 | public $post; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * The date of this payment. |
||
| 37 | * |
||
| 38 | * @var DateTime |
||
| 39 | */ |
||
| 40 | public $date; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The subscription. |
||
| 44 | * |
||
| 45 | * @var Subscription |
||
| 46 | */ |
||
| 47 | public $subscription; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The unique ID of this payment. |
||
| 51 | * |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | protected $id; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The title of this payment. |
||
| 58 | * |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | public $title; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The configuration ID. |
||
| 65 | * |
||
| 66 | * @var integer |
||
| 67 | */ |
||
| 68 | public $config_id; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * The key of this payment, used in URL's for security. |
||
| 72 | * |
||
| 73 | * @var string |
||
| 74 | */ |
||
| 75 | public $key; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Identifier for the source which started this payment. |
||
| 79 | * For example: 'woocommerce', 'gravityforms', 'easydigitaldownloads', etc. |
||
| 80 | * |
||
| 81 | * @var string |
||
| 82 | */ |
||
| 83 | public $source; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Unique ID at the source which started this payment, for example: |
||
| 87 | * - WooCommerce order ID. |
||
| 88 | * - Easy Digital Downloads payment ID. |
||
| 89 | * - Gravity Forms entry ID. |
||
| 90 | * |
||
| 91 | * @var string |
||
| 92 | */ |
||
| 93 | public $source_id; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * The purchase ID. |
||
| 97 | * |
||
| 98 | * @todo Is this required/used? |
||
| 99 | * @var string |
||
| 100 | */ |
||
| 101 | public $purchase_id; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * The transaction ID of this payment. |
||
| 105 | * |
||
| 106 | * @var string |
||
| 107 | */ |
||
| 108 | public $transaction_id; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * The order ID of this payment. |
||
| 112 | * |
||
| 113 | * @todo Is this required/used? |
||
| 114 | * @var string |
||
| 115 | */ |
||
| 116 | public $order_id; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * The amount of this payment, for example 18.95. |
||
| 120 | * |
||
| 121 | * @var Money |
||
| 122 | */ |
||
| 123 | protected $amount; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * The expiration period of this payment. |
||
| 127 | * |
||
| 128 | * @todo Is this required/used? |
||
| 129 | * @var string |
||
| 130 | */ |
||
| 131 | public $expiration_period; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * The language of the user who started this payment. |
||
| 135 | * |
||
| 136 | * @var string |
||
| 137 | */ |
||
| 138 | public $language; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * The locale of the user who started this payment. |
||
| 142 | * |
||
| 143 | * @var string |
||
| 144 | */ |
||
| 145 | public $locale; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * The entrance code of this payment. |
||
| 149 | * |
||
| 150 | * @todo Is this required/used? |
||
| 151 | * @var string |
||
| 152 | */ |
||
| 153 | public $entrance_code; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * The description of this payment. |
||
| 157 | * |
||
| 158 | * @var string |
||
| 159 | */ |
||
| 160 | public $description; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * The name of the consumer of this payment. |
||
| 164 | * |
||
| 165 | * @todo Is this required and should we add the 'consumer' part? |
||
| 166 | * @var string |
||
| 167 | */ |
||
| 168 | public $consumer_name; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * The account number of the consumer of this payment. |
||
| 172 | * |
||
| 173 | * @todo Is this required and should we add the 'consumer' part? |
||
| 174 | * @var string |
||
| 175 | */ |
||
| 176 | public $consumer_account_number; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * The IBAN of the consumer of this payment. |
||
| 180 | * |
||
| 181 | * @todo Is this required and should we add the 'consumer' part? |
||
| 182 | * @var string |
||
| 183 | */ |
||
| 184 | public $consumer_iban; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * The BIC of the consumer of this payment. |
||
| 188 | * |
||
| 189 | * @todo Is this required and should we add the 'consumer' part? |
||
| 190 | * @var string |
||
| 191 | */ |
||
| 192 | public $consumer_bic; |
||
| 193 | |||
| 194 | /** |
||
| 195 | * The city of the consumer of this payment. |
||
| 196 | * |
||
| 197 | * @todo Is this required and should we add the 'consumer' part? |
||
| 198 | * @var string |
||
| 199 | */ |
||
| 200 | public $consumer_city; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * The customer name of the consumer of this payment. |
||
| 204 | * |
||
| 205 | * @todo Is this required? |
||
| 206 | * @var string |
||
| 207 | */ |
||
| 208 | public $customer_name; |
||
| 209 | |||
| 210 | /** |
||
| 211 | * The address of the consumer of this payment. |
||
| 212 | * |
||
| 213 | * @todo Is this required? |
||
| 214 | * @var string |
||
| 215 | */ |
||
| 216 | public $address; |
||
| 217 | |||
| 218 | /** |
||
| 219 | * The city of the consumer of this payment. |
||
| 220 | * |
||
| 221 | * @todo Is this required? |
||
| 222 | * @var string |
||
| 223 | */ |
||
| 224 | public $city; |
||
| 225 | |||
| 226 | /** |
||
| 227 | * The ZIP of the consumer of this payment. |
||
| 228 | * |
||
| 229 | * @todo Is this required? |
||
| 230 | * @var string |
||
| 231 | */ |
||
| 232 | public $zip; |
||
| 233 | |||
| 234 | /** |
||
| 235 | * The country of the consumer of this payment. |
||
| 236 | * |
||
| 237 | * @todo Is this required? |
||
| 238 | * @var string |
||
| 239 | */ |
||
| 240 | public $country; |
||
| 241 | |||
| 242 | /** |
||
| 243 | * The telephone number of the consumer of this payment. |
||
| 244 | * |
||
| 245 | * @todo Is this required? |
||
| 246 | * @var string |
||
| 247 | */ |
||
| 248 | public $telephone_number; |
||
| 249 | |||
| 250 | /** |
||
| 251 | * The Google Analytics client ID of the user who started this payment. |
||
| 252 | * |
||
| 253 | * @var string |
||
| 254 | */ |
||
| 255 | public $analytics_client_id; |
||
| 256 | |||
| 257 | /** |
||
| 258 | * The status of this payment. |
||
| 259 | * |
||
| 260 | * @todo Check constant? |
||
| 261 | * @var string |
||
| 262 | */ |
||
| 263 | public $status; |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Status requests? |
||
| 267 | * |
||
| 268 | * @todo What is this? |
||
| 269 | * @var ? |
||
| 270 | */ |
||
| 271 | public $status_requests; |
||
| 272 | |||
| 273 | /** |
||
| 274 | * The email of the user who started this payment. |
||
| 275 | * |
||
| 276 | * @var string |
||
| 277 | */ |
||
| 278 | public $email; |
||
| 279 | |||
| 280 | /** |
||
| 281 | * The action URL for this payment. |
||
| 282 | * |
||
| 283 | * @var string |
||
| 284 | */ |
||
| 285 | public $action_url; |
||
| 286 | |||
| 287 | /** |
||
| 288 | * The payment method chosen by to user who started this payment. |
||
| 289 | * |
||
| 290 | * @var string |
||
| 291 | */ |
||
| 292 | public $method; |
||
| 293 | |||
| 294 | /** |
||
| 295 | * The issuer chosen by to user who started this payment. |
||
| 296 | * |
||
| 297 | * @var string |
||
| 298 | */ |
||
| 299 | public $issuer; |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Subscription ID. |
||
| 303 | * |
||
| 304 | * @todo Is this required? |
||
| 305 | * @var string |
||
| 306 | */ |
||
| 307 | public $subscription_id; |
||
| 308 | |||
| 309 | /** |
||
| 310 | * Flag to indicate a recurring payment |
||
| 311 | * |
||
| 312 | * @todo Is this required? |
||
| 313 | * @var boolean |
||
| 314 | */ |
||
| 315 | public $recurring; |
||
| 316 | |||
| 317 | /** |
||
| 318 | * The first name of the user who started this payment. |
||
| 319 | * |
||
| 320 | * @var string |
||
| 321 | */ |
||
| 322 | public $first_name; |
||
| 323 | |||
| 324 | /** |
||
| 325 | * The last name of the user who started this payment. |
||
| 326 | * |
||
| 327 | * @var string |
||
| 328 | */ |
||
| 329 | public $last_name; |
||
| 330 | |||
| 331 | /** |
||
| 332 | * The recurring type. |
||
| 333 | * |
||
| 334 | * @todo Improve documentation, is this used? |
||
| 335 | * @var string |
||
| 336 | */ |
||
| 337 | public $recurring_type; |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Meta. |
||
| 341 | * |
||
| 342 | * @var array |
||
| 343 | */ |
||
| 344 | public $meta; |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Start date if the payment is related to a specific period. |
||
| 348 | * |
||
| 349 | * @var DateTime |
||
| 350 | */ |
||
| 351 | public $start_date; |
||
| 352 | |||
| 353 | /** |
||
| 354 | * End date if the payment is related to a specific period. |
||
| 355 | * |
||
| 356 | * @var DateTime |
||
| 357 | */ |
||
| 358 | public $end_date; |
||
| 359 | |||
| 360 | /** |
||
| 361 | * User agent. |
||
| 362 | * |
||
| 363 | * @var string |
||
| 364 | */ |
||
| 365 | public $user_agent; |
||
| 366 | |||
| 367 | /** |
||
| 368 | * User IP address. |
||
| 369 | * |
||
| 370 | * @var string |
||
| 371 | */ |
||
| 372 | public $user_ip; |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Construct and initialize payment object. |
||
| 376 | * |
||
| 377 | * @param integer $post_id A payment post ID or null. |
||
| 378 | */ |
||
| 379 | public function __construct( $post_id = null ) { |
||
| 380 | $this->id = $post_id; |
||
| 381 | $this->date = new DateTime(); |
||
| 382 | $this->meta = array(); |
||
| 383 | |||
| 384 | $this->set_amount( new Money() ); |
||
| 385 | |||
| 386 | if ( null !== $post_id ) { |
||
| 387 | pronamic_pay_plugin()->payments_data_store->read( $this ); |
||
| 388 | } |
||
| 389 | } |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Get the ID of this payment. |
||
| 393 | * |
||
| 394 | * @return string |
||
| 395 | */ |
||
| 396 | public function get_id() { |
||
| 397 | return $this->id; |
||
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Set the ID of this payment. |
||
| 402 | * |
||
| 403 | * @param string $id Unique ID. |
||
| 404 | */ |
||
| 405 | public function set_id( $id ) { |
||
| 406 | $this->id = $id; |
||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Save payment. |
||
| 411 | * |
||
| 412 | * @return void |
||
| 413 | */ |
||
| 414 | public function save() { |
||
| 415 | pronamic_pay_plugin()->payments_data_store->update( $this ); |
||
| 416 | } |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Add a note to this payment. |
||
| 420 | * |
||
| 421 | * @param string $note The note to add. |
||
| 422 | */ |
||
| 423 | public function add_note( $note ) { |
||
| 424 | $commentdata = array( |
||
| 425 | 'comment_post_ID' => $this->id, |
||
| 426 | 'comment_content' => $note, |
||
| 427 | 'comment_type' => 'payment_note', |
||
| 428 | 'user_id' => get_current_user_id(), |
||
| 429 | 'comment_approved' => true, |
||
| 430 | ); |
||
| 431 | |||
| 432 | $comment_id = wp_insert_comment( $commentdata ); |
||
| 433 | |||
| 434 | return $comment_id; |
||
| 435 | } |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Get the source identifier of this payment. |
||
| 439 | * |
||
| 440 | * @return string |
||
| 441 | */ |
||
| 442 | public function get_source() { |
||
| 443 | return $this->source; |
||
| 444 | } |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Get the source ID of this payment. |
||
| 448 | * |
||
| 449 | * @return string |
||
| 450 | */ |
||
| 451 | public function get_source_id() { |
||
| 452 | return $this->source_id; |
||
| 453 | } |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Get the source text of this payment. |
||
| 457 | * |
||
| 458 | * @return string |
||
| 459 | */ |
||
| 460 | public function get_source_text() { |
||
| 461 | $text = $this->get_source() . '<br />' . $this->get_source_id(); |
||
| 462 | |||
| 463 | $text = apply_filters( 'pronamic_payment_source_text_' . $this->get_source(), $text, $this ); |
||
| 464 | $text = apply_filters( 'pronamic_payment_source_text', $text, $this ); |
||
| 465 | |||
| 466 | return $text; |
||
| 467 | } |
||
| 468 | |||
| 469 | /** |
||
| 470 | * Get the order ID of this payment. |
||
| 471 | * |
||
| 472 | * @return string |
||
| 473 | */ |
||
| 474 | public function get_order_id() { |
||
| 475 | return $this->order_id; |
||
| 476 | } |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Get the payment amount. |
||
| 480 | * |
||
| 481 | * @return Money |
||
| 482 | */ |
||
| 483 | public function get_amount() { |
||
| 484 | return $this->amount; |
||
| 485 | } |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Set the payment amount. |
||
| 489 | * |
||
| 490 | * @param Money $amount Money object. |
||
| 491 | */ |
||
| 492 | public function set_amount( Money $amount ) { |
||
| 493 | $this->amount = $amount; |
||
| 494 | } |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Get the payment currency. |
||
| 498 | * |
||
| 499 | * @return Currency |
||
| 500 | */ |
||
| 501 | public function get_currency() { |
||
| 502 | return $this->get_amount()->get_currency()->get_alphabetic_code(); |
||
| 503 | } |
||
| 504 | |||
| 505 | /** |
||
| 506 | * Get currency numeric code |
||
| 507 | * |
||
| 508 | * @return string|null |
||
| 509 | */ |
||
| 510 | public function get_currency_numeric_code() { |
||
| 511 | return $this->get_amount()->get_currency()->get_numeric_code(); |
||
| 512 | } |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Get the payment method. |
||
| 516 | * |
||
| 517 | * @todo Constant? |
||
| 518 | * @return string |
||
| 519 | */ |
||
| 520 | public function get_method() { |
||
| 521 | return $this->method; |
||
| 522 | } |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Get the payment issuer. |
||
| 526 | * |
||
| 527 | * @return string |
||
| 528 | */ |
||
| 529 | public function get_issuer() { |
||
| 530 | return $this->issuer; |
||
| 531 | } |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Get the payment language. |
||
| 535 | * |
||
| 536 | * @return string |
||
| 537 | */ |
||
| 538 | public function get_language() { |
||
| 539 | return $this->language; |
||
| 540 | } |
||
| 541 | |||
| 542 | /** |
||
| 543 | * Get the payment locale. |
||
| 544 | * |
||
| 545 | * @return string |
||
| 546 | */ |
||
| 547 | public function get_locale() { |
||
| 548 | return $this->locale; |
||
| 549 | } |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Get the payment description. |
||
| 553 | * |
||
| 554 | * @return string |
||
| 555 | */ |
||
| 556 | public function get_description() { |
||
| 557 | return $this->description; |
||
| 558 | } |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Set the transaction ID. |
||
| 562 | * |
||
| 563 | * @param string $transaction_id Transaction ID. |
||
| 564 | */ |
||
| 565 | public function set_transaction_id( $transaction_id ) { |
||
| 566 | $this->transaction_id = $transaction_id; |
||
| 567 | } |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Get the payment transaction ID. |
||
| 571 | * |
||
| 572 | * @return string |
||
| 573 | */ |
||
| 574 | public function get_transaction_id() { |
||
| 575 | return $this->transaction_id; |
||
| 576 | } |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Get the payment status. |
||
| 580 | * |
||
| 581 | * @todo Constant? |
||
| 582 | * @return string |
||
| 583 | */ |
||
| 584 | public function get_status() { |
||
| 585 | return $this->status; |
||
| 586 | } |
||
| 587 | |||
| 588 | /** |
||
| 589 | * Set the payment status. |
||
| 590 | * |
||
| 591 | * @param string $status Status. |
||
| 592 | */ |
||
| 593 | public function set_status( $status ) { |
||
| 594 | $this->status = $status; |
||
| 595 | } |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Get the meta value of this specified meta key. |
||
| 599 | * |
||
| 600 | * @param string $key Meta key. |
||
| 601 | * @return mixed |
||
| 602 | */ |
||
| 603 | public function get_meta( $key ) { |
||
| 604 | $key = '_pronamic_payment_' . $key; |
||
| 605 | |||
| 606 | return get_post_meta( $this->id, $key, true ); |
||
| 607 | } |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Set meta value at the specified key. |
||
| 611 | * |
||
| 612 | * @param string $key Meta key. |
||
| 613 | * @param string $value Meta value. |
||
| 614 | */ |
||
| 615 | public function set_meta( $key, $value ) { |
||
| 616 | $this->meta[ $key ] = $value; |
||
| 617 | } |
||
| 618 | |||
| 619 | /** |
||
| 620 | * Get the pay redirect URL. |
||
| 621 | * |
||
| 622 | * @return string |
||
| 623 | */ |
||
| 624 | public function get_pay_redirect_url() { |
||
| 625 | return add_query_arg( 'payment_redirect', $this->id, home_url( '/' ) ); |
||
| 626 | } |
||
| 627 | |||
| 628 | /** |
||
| 629 | * Get the return URL for this payment. This URL is passed to the payment providers / gateways |
||
| 630 | * so they know where they should return users to. |
||
| 631 | * |
||
| 632 | * @return string |
||
| 633 | */ |
||
| 634 | public function get_return_url() { |
||
| 635 | $url = add_query_arg( |
||
| 636 | array( |
||
| 637 | 'payment' => $this->id, |
||
| 638 | 'key' => $this->key, |
||
| 639 | ), |
||
| 640 | home_url( '/' ) |
||
| 641 | ); |
||
| 642 | |||
| 643 | return $url; |
||
| 644 | } |
||
| 645 | |||
| 646 | /** |
||
| 647 | * Get action URL. |
||
| 648 | * |
||
| 649 | * @return string |
||
| 650 | */ |
||
| 651 | public function get_action_url() { |
||
| 652 | $action_url = $this->action_url; |
||
| 653 | |||
| 654 | $amount = $this->get_amount()->get_amount(); |
||
| 655 | |||
| 656 | if ( empty( $amount ) ) { |
||
| 657 | $status = $this->get_status(); |
||
| 658 | |||
| 659 | $this->set_status( Statuses::SUCCESS ); |
||
| 660 | |||
| 661 | $action_url = $this->get_return_redirect_url(); |
||
| 662 | |||
| 663 | $this->set_status( $status ); |
||
| 664 | } |
||
| 665 | |||
| 666 | return $action_url; |
||
| 667 | } |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Set the action URL. |
||
| 671 | * |
||
| 672 | * @param string $action_url Action URL. |
||
| 673 | */ |
||
| 674 | public function set_action_url( $action_url ) { |
||
| 675 | $this->action_url = $action_url; |
||
| 676 | } |
||
| 677 | |||
| 678 | /** |
||
| 679 | * Get the return redirect URL for this payment. This URL is used after a user is returned |
||
| 680 | * from a payment provider / gateway to WordPress. It allows WordPress payment extensions |
||
| 681 | * to redirect users to the correct URL. |
||
| 682 | * |
||
| 683 | * @return string |
||
| 684 | */ |
||
| 685 | public function get_return_redirect_url() { |
||
| 686 | $url = home_url( '/' ); |
||
| 687 | |||
| 688 | $url = apply_filters( 'pronamic_payment_redirect_url', $url, $this ); |
||
| 689 | $url = apply_filters( 'pronamic_payment_redirect_url_' . $this->source, $url, $this ); |
||
| 690 | |||
| 691 | return $url; |
||
| 692 | } |
||
| 693 | |||
| 694 | /** |
||
| 695 | * Get the redirect URL for this payment. |
||
| 696 | * |
||
| 697 | * @deprecated 4.1.2 Use get_return_redirect_url() |
||
| 698 | * @return string |
||
| 699 | */ |
||
| 700 | public function get_redirect_url() { |
||
| 704 | } |
||
| 705 | |||
| 706 | /** |
||
| 707 | * Get source description. |
||
| 708 | * |
||
| 709 | * @return string |
||
| 710 | */ |
||
| 711 | public function get_source_description() { |
||
| 712 | $description = $this->source; |
||
| 713 | |||
| 714 | $description = apply_filters( 'pronamic_payment_source_description', $description, $this ); |
||
| 715 | $description = apply_filters( 'pronamic_payment_source_description_' . $this->source, $description, $this ); |
||
| 716 | |||
| 717 | return $description; |
||
| 718 | } |
||
| 719 | |||
| 720 | /** |
||
| 721 | * Get the source link for this payment. |
||
| 722 | * |
||
| 723 | * @return string|null |
||
| 724 | */ |
||
| 725 | public function get_source_link() { |
||
| 726 | $url = null; |
||
| 727 | |||
| 728 | $url = apply_filters( 'pronamic_payment_source_url', $url, $this ); |
||
| 729 | $url = apply_filters( 'pronamic_payment_source_url_' . $this->source, $url, $this ); |
||
| 730 | |||
| 731 | return $url; |
||
| 732 | } |
||
| 733 | |||
| 734 | /** |
||
| 735 | * Get provider link for this payment. |
||
| 736 | * |
||
| 737 | * @return string |
||
| 738 | */ |
||
| 739 | public function get_provider_link() { |
||
| 740 | $url = null; |
||
| 741 | |||
| 742 | $config_id = get_post_meta( $this->id, '_pronamic_payment_config_id', true ); |
||
| 743 | $gateway_id = get_post_meta( $config_id, '_pronamic_gateway_id', true ); |
||
|
|
|||
| 744 | |||
| 745 | $url = apply_filters( 'pronamic_payment_provider_url', $url, $this ); |
||
| 746 | $url = apply_filters( 'pronamic_payment_provider_url_' . $gateway_id, $url, $this ); |
||
| 747 | |||
| 748 | return $url; |
||
| 749 | } |
||
| 750 | |||
| 751 | /** |
||
| 752 | * Get subscription. |
||
| 753 | * |
||
| 754 | * @return Subscription |
||
| 755 | */ |
||
| 756 | public function get_subscription() { |
||
| 757 | if ( is_object( $this->subscription ) ) { |
||
| 758 | return $this->subscription; |
||
| 759 | } |
||
| 760 | |||
| 761 | if ( empty( $this->subscription_id ) ) { |
||
| 762 | return false; |
||
| 763 | } |
||
| 764 | |||
| 765 | $this->subscription = new Subscription( $this->subscription_id ); |
||
| 766 | |||
| 767 | return $this->subscription; |
||
| 768 | } |
||
| 769 | |||
| 770 | /** |
||
| 771 | * Format string |
||
| 772 | * |
||
| 773 | * @see https://github.com/woocommerce/woocommerce/blob/v2.2.3/includes/abstracts/abstract-wc-email.php#L187-L195 |
||
| 774 | * |
||
| 775 | * @param string $string The string to format. |
||
| 776 | * @return string |
||
| 777 | */ |
||
| 778 | public function format_string( $string ) { |
||
| 779 | // Replacements definition. |
||
| 780 | $replacements = array( |
||
| 781 | '{order_id}' => $this->get_order_id(), |
||
| 782 | '{payment_id}' => $this->get_id(), |
||
| 783 | ); |
||
| 784 | |||
| 785 | // Find and replace. |
||
| 786 | $string = str_replace( |
||
| 787 | array_keys( $replacements ), |
||
| 788 | array_values( $replacements ), |
||
| 789 | $string, |
||
| 790 | $count |
||
| 791 | ); |
||
| 792 | |||
| 793 | // Make sure there is an dynamic part in the order ID. |
||
| 794 | // @see https://secure.ogone.com/ncol/param_cookbook.asp. |
||
| 795 | if ( 0 === $count ) { |
||
| 796 | $string .= $this->get_id(); |
||
| 797 | } |
||
| 798 | |||
| 799 | return $string; |
||
| 800 | } |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Set consumer name. |
||
| 804 | * |
||
| 805 | * @param string $name Name. |
||
| 806 | */ |
||
| 807 | public function set_consumer_name( $name ) { |
||
| 809 | } |
||
| 810 | |||
| 811 | /** |
||
| 812 | * Set consumer account number. |
||
| 813 | * |
||
| 814 | * @param string $account_number Account number. |
||
| 815 | */ |
||
| 816 | public function set_consumer_account_number( $account_number ) { |
||
| 817 | $this->consumer_account_number = $account_number; |
||
| 818 | } |
||
| 819 | |||
| 820 | /** |
||
| 821 | * Set consumer IBAN. |
||
| 822 | * |
||
| 823 | * @param string $iban IBAN. |
||
| 824 | */ |
||
| 825 | public function set_consumer_iban( $iban ) { |
||
| 826 | $this->consumer_iban = $iban; |
||
| 827 | } |
||
| 828 | |||
| 829 | /** |
||
| 830 | * Set consumer BIC. |
||
| 831 | * |
||
| 832 | * @param string $bic BIC. |
||
| 833 | */ |
||
| 834 | public function set_consumer_bic( $bic ) { |
||
| 835 | $this->consumer_bic = $bic; |
||
| 836 | } |
||
| 837 | |||
| 838 | /** |
||
| 839 | * Set consumer city. |
||
| 840 | * |
||
| 841 | * @param string $city City. |
||
| 842 | */ |
||
| 843 | public function set_consumer_city( $city ) { |
||
| 844 | $this->consumer_city = $city; |
||
| 845 | } |
||
| 846 | |||
| 847 | /** |
||
| 848 | * Get payment email. |
||
| 849 | * |
||
| 850 | * @return string |
||
| 851 | */ |
||
| 852 | public function get_email() { |
||
| 853 | return $this->email; |
||
| 854 | } |
||
| 855 | |||
| 856 | /** |
||
| 857 | * Get first name. |
||
| 858 | * |
||
| 859 | * @return string |
||
| 860 | */ |
||
| 861 | public function get_first_name() { |
||
| 862 | return $this->first_name; |
||
| 863 | } |
||
| 864 | |||
| 865 | /** |
||
| 866 | * Get last name. |
||
| 867 | * |
||
| 868 | * @return string |
||
| 869 | */ |
||
| 870 | public function get_last_name() { |
||
| 871 | return $this->last_name; |
||
| 872 | } |
||
| 873 | |||
| 874 | /** |
||
| 875 | * Get customer name. |
||
| 876 | * |
||
| 877 | * @return string |
||
| 878 | */ |
||
| 879 | public function get_customer_name() { |
||
| 880 | return $this->customer_name; |
||
| 881 | } |
||
| 882 | |||
| 883 | /** |
||
| 884 | * Get address. |
||
| 885 | * |
||
| 886 | * @return string |
||
| 887 | */ |
||
| 888 | public function get_address() { |
||
| 889 | return $this->address; |
||
| 890 | } |
||
| 891 | |||
| 892 | /** |
||
| 893 | * Get city. |
||
| 894 | * |
||
| 895 | * @return string |
||
| 896 | */ |
||
| 897 | public function get_city() { |
||
| 898 | return $this->city; |
||
| 899 | } |
||
| 900 | |||
| 901 | /** |
||
| 902 | * Get ZIP. |
||
| 903 | * |
||
| 904 | * @return string |
||
| 905 | */ |
||
| 906 | public function get_zip() { |
||
| 908 | } |
||
| 909 | |||
| 910 | /** |
||
| 911 | * Get country. |
||
| 912 | * |
||
| 913 | * @return string |
||
| 914 | */ |
||
| 915 | public function get_country() { |
||
| 916 | return $this->country; |
||
| 917 | } |
||
| 918 | |||
| 919 | /** |
||
| 920 | * Get telephone number. |
||
| 921 | * |
||
| 922 | * @return string |
||
| 923 | */ |
||
| 924 | public function get_telephone_number() { |
||
| 925 | return $this->telephone_number; |
||
| 926 | } |
||
| 927 | |||
| 928 | /** |
||
| 929 | * Get Google Analytics client ID. |
||
| 930 | * |
||
| 931 | * @return string |
||
| 932 | */ |
||
| 933 | public function get_analytics_client_id() { |
||
| 934 | return $this->analytics_client_id; |
||
| 935 | } |
||
| 936 | |||
| 937 | /** |
||
| 938 | * Get entrance code. |
||
| 939 | * |
||
| 940 | * @return string |
||
| 941 | */ |
||
| 942 | public function get_entrance_code() { |
||
| 943 | return $this->entrance_code; |
||
| 944 | } |
||
| 945 | |||
| 946 | /** |
||
| 947 | * Set the credit card to use for this payment. |
||
| 948 | * |
||
| 949 | * @param CreditCard $credit_card Credit Card. |
||
| 950 | */ |
||
| 951 | public function set_credit_card( $credit_card ) { |
||
| 952 | $this->credit_card = $credit_card; |
||
| 953 | } |
||
| 954 | |||
| 955 | /** |
||
| 956 | * Get the credit card to use for this payment. |
||
| 957 | * |
||
| 958 | * @return CreditCard|null |
||
| 959 | */ |
||
| 960 | public function get_credit_card() { |
||
| 961 | return $this->credit_card; |
||
| 962 | } |
||
| 963 | |||
| 964 | /** |
||
| 965 | * Get payment subscription ID. |
||
| 966 | * |
||
| 967 | * @return string |
||
| 968 | */ |
||
| 969 | public function get_subscription_id() { |
||
| 971 | } |
||
| 972 | |||
| 973 | /** |
||
| 974 | * Get reucrring. |
||
| 975 | * |
||
| 976 | * @return TODO |
||
| 977 | */ |
||
| 978 | public function get_recurring() { |
||
| 979 | return $this->recurring; |
||
| 980 | } |
||
| 981 | } |
||
| 982 |