wp-pay-gateways /
mollie
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Mollie profile data store. |
||
| 4 | * |
||
| 5 | * @author Pronamic <[email protected]> |
||
| 6 | * @copyright 2005-2020 Pronamic |
||
| 7 | * @license GPL-3.0-or-later |
||
| 8 | * @package Pronamic\WordPress\Pay |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace Pronamic\WordPress\Pay\Gateways\Mollie; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Title: Mollie profile data store |
||
| 15 | * Description: |
||
| 16 | * Copyright: 2005-2020 Pronamic |
||
| 17 | * Company: Pronamic |
||
| 18 | * |
||
| 19 | * @author Remco Tolsma |
||
| 20 | * @version 3.0.0 |
||
| 21 | * @since 3.0.0 |
||
| 22 | */ |
||
| 23 | class ProfileDataStore { |
||
| 24 | /** |
||
| 25 | * Get profile data for specified Mollie profile. |
||
| 26 | * |
||
| 27 | * @param Profile $profile Profile. |
||
| 28 | * @return object|null |
||
| 29 | */ |
||
| 30 | public function get_profile( Profile $profile ) { |
||
| 31 | global $wpdb; |
||
| 32 | |||
| 33 | $id = $profile->get_id(); |
||
| 34 | |||
| 35 | if ( null === $id ) { |
||
| 36 | return null; |
||
| 37 | } |
||
| 38 | |||
| 39 | $query = $wpdb->prepare( "SELECT * FROM $wpdb->pronamic_pay_mollie_profiles WHERE mollie_id = %s LIMIT 1;", $id ); |
||
| 40 | |||
| 41 | $data = $wpdb->get_row( $query ); |
||
| 42 | |||
| 43 | return $data; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Save Mollie profile. |
||
| 48 | * |
||
| 49 | * @param Profile $profile Profile. |
||
| 50 | * @param array $data Data. |
||
| 51 | * @param array $format Format. |
||
| 52 | * @return int |
||
| 53 | */ |
||
| 54 | public function save_profile( Profile $profile, $data = array(), $format = array() ) { |
||
| 55 | global $wpdb; |
||
| 56 | |||
| 57 | $id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->pronamic_pay_mollie_profiles WHERE mollie_id = %s", $profile->get_id() ) ); |
||
| 58 | |||
| 59 | $data['email'] = $profile->email; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 60 | $format['email'] = '%s'; |
||
| 61 | |||
| 62 | $data['name'] = $profile->name; |
||
|
0 ignored issues
–
show
|
|||
| 63 | $format['name'] = '%s'; |
||
| 64 | |||
| 65 | if ( null === $id ) { |
||
| 66 | $data['mollie_id'] = $profile->get_id(); |
||
| 67 | $foramt['mollie_id'] = '%s'; |
||
| 68 | |||
| 69 | $result = $wpdb->insert( |
||
| 70 | $wpdb->pronamic_pay_mollie_profiles, |
||
| 71 | $data, |
||
| 72 | $format |
||
| 73 | ); |
||
| 74 | |||
| 75 | if ( false === $result ) { |
||
| 76 | \WP_CLI::error( |
||
|
0 ignored issues
–
show
The type
WP_CLI was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 77 | sprintf( |
||
| 78 | 'Database error: %s.', |
||
| 79 | $wpdb->last_error |
||
| 80 | ) |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | |||
| 84 | $id = $wpdb->insert_id; |
||
| 85 | } else { |
||
| 86 | $result = $wpdb->update( |
||
| 87 | $wpdb->pronamic_pay_mollie_profiles, |
||
| 88 | $data, |
||
| 89 | array( |
||
| 90 | 'id' => $id, |
||
| 91 | ), |
||
| 92 | $format, |
||
| 93 | array( |
||
| 94 | 'id' => '%d', |
||
| 95 | ) |
||
| 96 | ); |
||
| 97 | |||
| 98 | if ( false === $result ) { |
||
| 99 | \WP_CLI::error( |
||
| 100 | sprintf( |
||
| 101 | 'Database error: %s.', |
||
| 102 | $wpdb->last_error |
||
| 103 | ) |
||
| 104 | ); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | return $id; |
||
| 109 | } |
||
| 110 | } |
||
| 111 |