class-buyer-fingerprinting-service.php
1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* Class Buyer_Fingerprinting_Service
*
* @package WCPay\Fraud_Prevention
*/
namespace WCPay\Fraud_Prevention;
use WC_Geolocation;
/**
* Class Buyer_Fingerprinting_Service
*/
class Buyer_Fingerprinting_Service {
/**
* Singleton instance.
*
* @var Buyer_Fingerprinting_Service
*/
private static $instance;
/**
* Returns singleton instance.
*
* @return Buyer_Fingerprinting_Service
*/
public static function get_instance(): self {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Sets a instance to be used in request cycle.
* Introduced primarily for supporting unit tests.
*
* @param Buyer_Fingerprinting_Service|null $instance Instance of self.
*/
public static function set_instance( self $instance = null ) {
self::$instance = $instance;
}
/**
* Hashes customer data for the fraud prevention.
*
* @param string $data The data you want to hash.
*
* @return string Hashed data.
*/
public function hash_data_for_fraud_prevention( string $data ): string {
return hash( 'sha512', $data, false );
}
/**
* Returns fraud prevention data for an order.
*
* @param string $fingerprint User fingerprint.
*
* @return string[] An array of hashed data for an order.
*/
public function get_hashed_data_for_customer( $fingerprint ): array {
return [
'fraud_prevention_data_shopper_ip_hash' => $this->hash_data_for_fraud_prevention( WC_Geolocation::get_ip_address() ),
'fraud_prevention_data_shopper_ua_hash' => $fingerprint,
];
}
}