PaiementPro4Give_Moov_Money   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 68
c 1
b 0
f 1
dl 0
loc 108
rs 10
wmc 11

2 Methods

Rating   Name   Duplication   Size   Complexity  
C process_donation() 0 102 10
A __construct() 0 3 1
1
<?php
2
/**
3
 * PaiementPro for Give | MTN Money
4
 *
5
 * @since 1.0.0
6
 */
7
8
// Bailout, if accessed directly.
9
if ( ! defined( 'ABSPATH' ) ) {
10
	exit;
11
}
12
13
class PaiementPro4Give_Moov_Money {
14
	public function __construct() {
15
		add_action( 'give_gateway_paiementpro_moov_money', [ $this, 'process_donation' ] );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
		/** @scrutinizer ignore-call */ 
16
  add_action( 'give_gateway_paiementpro_moov_money', [ $this, 'process_donation' ] );
Loading history...
16
		add_action( 'give_paiementpro_moov_money_cc_form', '__return_false' );
17
	}
18
19
	public function process_donation( $data ) {
20
		// Check for any stored errors.
21
		$errors = give_get_errors();
0 ignored issues
show
Bug introduced by
The function give_get_errors was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
		$errors = /** @scrutinizer ignore-call */ give_get_errors();
Loading history...
22
23
		if ( ! $errors ) {
24
25
			$form_id         = ! empty( $data['post_data']['give-form-id'] ) ? intval( $data['post_data']['give-form-id'] ) : false;
26
			$first_name      = ! empty( $data['post_data']['give_first'] ) ? $data['post_data']['give_first'] : '';
27
			$last_name       = ! empty( $data['post_data']['give_last'] ) ? $data['post_data']['give_last'] : '';
28
			$email           = ! empty( $data['post_data']['give_email'] ) ? $data['post_data']['give_email'] : '';
29
			$donation_key    = ! empty( $data['purchase_key'] ) ? $data['purchase_key'] : '';
30
			$currency        = give_get_currency( $form_id );
0 ignored issues
show
Bug introduced by
The function give_get_currency was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
			$currency        = /** @scrutinizer ignore-call */ give_get_currency( $form_id );
Loading history...
31
32
			// Setup the donation details.
33
			$data_to_send = array(
34
				'price'           => $data['price'],
35
				'give_form_title' => $data['post_data']['give-form-title'],
36
				'give_form_id'    => $form_id,
37
				'give_price_id'   => isset( $data['post_data']['give-price-id'] ) ? $data['post_data']['give-price-id'] : '',
38
				'date'            => $data['date'],
39
				'user_email'      => $email,
40
				'purchase_key'    => $data['purchase_key'],
41
				'currency'        => $currency,
42
				'user_info'       => $data['user_info'],
43
				'status'          => 'pending',
44
				'gateway'         => $data['gateway'],
45
			);
46
47
			// Record the pending payment.
48
			$donation_id = give_insert_payment( $data_to_send );
0 ignored issues
show
Bug introduced by
The function give_insert_payment was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
			$donation_id = /** @scrutinizer ignore-call */ give_insert_payment( $data_to_send );
Loading history...
49
50
			// Verify donation payment.
51
			if ( ! $donation_id ) {
52
53
				// Record the error.
54
				give_record_gateway_error(
0 ignored issues
show
Bug introduced by
The function give_record_gateway_error was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
				/** @scrutinizer ignore-call */ 
55
    give_record_gateway_error(
Loading history...
55
					__( 'Payment Error', 'paiementpro-for-give' ),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
					/** @scrutinizer ignore-call */ 
56
     __( 'Payment Error', 'paiementpro-for-give' ),
Loading history...
56
					sprintf(
57
					/* translators: %s: payment data */
58
						__( 'Payment creation failed before processing payment via PaiementPro. Payment data: %s', 'paiementpro-for-give' ),
59
						wp_json_encode( $data )
0 ignored issues
show
Bug introduced by
The function wp_json_encode was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
						/** @scrutinizer ignore-call */ 
60
      wp_json_encode( $data )
Loading history...
60
					),
61
					$donation_id
62
				);
63
64
				// Problems? Send back.
65
				give_send_back_to_checkout( '?payment-mode=' . $data['post_data']['payment-mode'] );
0 ignored issues
show
Bug introduced by
The function give_send_back_to_checkout was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
				/** @scrutinizer ignore-call */ 
66
    give_send_back_to_checkout( '?payment-mode=' . $data['post_data']['payment-mode'] );
Loading history...
66
			}
67
68
			// Auto set payment to abandoned in one hour if donor is not able to donate in that time.
69
			wp_schedule_single_event( current_time( 'timestamp', 1 ) + HOUR_IN_SECONDS, 'paiementpro4give_set_donation_abandoned', [ $donation_id ] );
0 ignored issues
show
Bug introduced by
The constant HOUR_IN_SECONDS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function current_time was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
			wp_schedule_single_event( /** @scrutinizer ignore-call */ current_time( 'timestamp', 1 ) + HOUR_IN_SECONDS, 'paiementpro4give_set_donation_abandoned', [ $donation_id ] );
Loading history...
Bug introduced by
The function wp_schedule_single_event was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
			/** @scrutinizer ignore-call */ 
70
   wp_schedule_single_event( current_time( 'timestamp', 1 ) + HOUR_IN_SECONDS, 'paiementpro4give_set_donation_abandoned', [ $donation_id ] );
Loading history...
70
71
72
			$url         = paiementpro4give_get_api_url();
73
			$merchant_id = paiementpro4give_get_merchant_id();
74
			$args        = [
75
				'headers' => [
76
					'Content-Type' => 'application/x-www-form-urlencoded'
77
				],
78
				'body'    => [
79
					'merchantId'      => $merchant_id,
80
					'currency'        => 952,
81
					'amount'          => $data['price'],
82
					'channel'         => 'FLOOZ',
83
					'customer_id'     => '',
84
					'description'     => 'Hello',
85
					'email'           => $email,
86
					'firstname'       => $first_name,
87
					'lastname'        => $last_name,
88
					'phone_mobile'    => '9876543210',
89
					'referenceNumber' => $donation_key,
90
					'notificationURL' => give_get_success_page_uri(),
0 ignored issues
show
Bug introduced by
The function give_get_success_page_uri was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
					'notificationURL' => /** @scrutinizer ignore-call */ give_get_success_page_uri(),
Loading history...
91
					'returnContext'   => wp_json_encode( [
92
						'id_order' => $donation_id,
93
					] ),
94
				],
95
			];
96
			$response     = wp_remote_post( "{$url}init2.php", $args );
0 ignored issues
show
Bug introduced by
The function wp_remote_post was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

96
			$response     = /** @scrutinizer ignore-call */ wp_remote_post( "{$url}init2.php", $args );
Loading history...
97
			$responseBody = wp_remote_retrieve_body( $response );
0 ignored issues
show
Bug introduced by
The function wp_remote_retrieve_body was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

97
			$responseBody = /** @scrutinizer ignore-call */ wp_remote_retrieve_body( $response );
Loading history...
98
			$responseCode = wp_remote_retrieve_response_code( $response );
0 ignored issues
show
Bug introduced by
The function wp_remote_retrieve_response_code was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

98
			$responseCode = /** @scrutinizer ignore-call */ wp_remote_retrieve_response_code( $response );
Loading history...
99
100
			if ( 200 === $responseCode ) {
101
102
				$responseBodyParts = explode( '|', $responseBody );
103
				$sessionId         = $responseBodyParts[1];
104
105
				$redirect_to_url = add_query_arg(
0 ignored issues
show
Bug introduced by
The function add_query_arg was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
				$redirect_to_url = /** @scrutinizer ignore-call */ add_query_arg(
Loading history...
106
					[
107
						'sessionid' => $sessionId,
108
						'id' => $donation_id,
109
					],
110
					"{$url}processing.php"
111
				);
112
113
			} else {
114
				// Send user to failed page and change donation status to failed as well.
115
				give_update_payment_status( $donation_id, 'failed' );
0 ignored issues
show
Bug introduced by
The function give_update_payment_status was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

115
				/** @scrutinizer ignore-call */ 
116
    give_update_payment_status( $donation_id, 'failed' );
Loading history...
116
				$redirect_to_url = give_get_failed_transaction_uri();
0 ignored issues
show
Bug introduced by
The function give_get_failed_transaction_uri was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

116
				$redirect_to_url = /** @scrutinizer ignore-call */ give_get_failed_transaction_uri();
Loading history...
117
			}
118
119
			wp_redirect( $redirect_to_url );
0 ignored issues
show
Bug introduced by
The function wp_redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

119
			/** @scrutinizer ignore-call */ 
120
   wp_redirect( $redirect_to_url );
Loading history...
120
			give_die();
0 ignored issues
show
Bug introduced by
The function give_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

120
			/** @scrutinizer ignore-call */ 
121
   give_die();
Loading history...
121
		}
122
	}
123
}
124
125
new PaiementPro4Give_Moov_Money();