paiementpro4give_verify_payment()   B
last analyzed

Complexity

Conditions 7
Paths 16

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 7
eloc 16
c 1
b 1
f 0
nc 16
nop 0
dl 0
loc 28
rs 8.8333
1
<?php
2
/**
3
 * PaiementPro for Give | Actions
4
 *
5
 * @since 1.0.0
6
 */
7
8
// Bailout, if accessed directly.
9
if ( ! defined( 'ABSPATH' ) ) {
10
	exit;
11
}
12
13
/**
14
 * This function will validate payment on donation receipt page.
15
 *
16
 * @since 1.0.0
17
 *
18
 * @return void
19
 */
20
function paiementpro4give_verify_payment() {
21
22
	$getData       = give_clean( $_GET );
0 ignored issues
show
Bug introduced by
The function give_clean 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

22
	$getData       = /** @scrutinizer ignore-call */ give_clean( $_GET );
Loading history...
23
	$donationId    = ! empty( $getData['order_id'] ) ? $getData['order_id'] : false;
24
	$transactionId = ! empty( $getData['pp_status'] ) ? $getData['pp_status'] : '';
25
26
	// Bailout, if donation id not received from paiementpro gateway.
27
	if ( ! $donationId ) {
28
		return;
29
	}
30
31
	$donationGateway   = give_get_payment_gateway( $donationId );
0 ignored issues
show
Bug introduced by
The function give_get_payment_gateway 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

31
	$donationGateway   = /** @scrutinizer ignore-call */ give_get_payment_gateway( $donationId );
Loading history...
32
	$supportedGateways = paiementpro4give_get_supported_payment_methods();
33
34
	// Bailout, if not `$donationGateway` payment gateway.
35
	if ( ! in_array( $donationGateway, $supportedGateways, true ) ) {
36
		return;
37
	}
38
39
	$credentialId  = paiementpro4give_get_credential_id();
40
	$merchantId    = paiementpro4give_get_merchant_id();
41
	$successStatus = sha1("{$donationId}success{$merchantId}{$credentialId}" );
42
43
	// Success, if transaction id exists, else failed.
44
	if ( ! empty( $transactionId ) && $transactionId === $successStatus ) {
45
		give_update_payment_status( $donationId, 'publish' );
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

45
		/** @scrutinizer ignore-call */ 
46
  give_update_payment_status( $donationId, 'publish' );
Loading history...
46
	} else {
47
		give_update_payment_status( $donationId, 'failed' );
48
	}
49
}
50
51
add_action( 'init', 'paiementpro4give_verify_payment' );
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

51
/** @scrutinizer ignore-call */ 
52
add_action( 'init', 'paiementpro4give_verify_payment' );
Loading history...