Failed Conditions
Push — develop ( 39b9b1...0f6081 )
by Reüel
22:55
created

tests/src/DirectTransactionTest.php (3 issues)

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\MultiSafepay;
4
5
use stdClass;
6
use WP_Http;
7
use WP_UnitTestCase;
8
use Pronamic\WordPress\Pay\Core\Server;
9
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\MultiSafepay;
10
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Config;
11
12
class DirectTransactionTest extends WP_UnitTestCase {
13
	/**
14
	 * Pre HTTP request
15
	 *
16
	 * @link https://github.com/WordPress/WordPress/blob/3.9.1/wp-includes/class-http.php#L150-L164
17
	 * @return string
18
	 */
19
	public function pre_http_request( $preempt, $request, $url ) {
20
		$response = file_get_contents( dirname( dirname( __FILE__ ) ) . '/Mock/direct-transaction-response.http' );
21
22
		$processed_response = WP_Http::processResponse( $response );
23
24
		$processed_headers = WP_Http::processHeaders( $processed_response['headers'], $url );
25
26
		$processed_headers['body'] = $processed_response['body'];
27
28
		return $processed_headers;
29
	}
30
31
	public function http_api_debug( $response, $context, $class, $args, $url ) {
32
33
	}
34
35
	public function test_init() {
36
		// Actions
37
		//add_action( 'http_api_debug', array( $this, 'http_api_debug' ), 10, 5 );
38
		add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 );
39
40
		// Config
41
		$config = new Config();
42
43
		$config->mode       = getenv( 'MULTISAFEPAY_MODE' );
44
		$config->account_id = getenv( 'MULTISAFEPAY_ACCOUNT_ID' );
45
		$config->site_id    = getenv( 'MULTISAFEPAY_SITE_ID' );
46
		$config->site_code  = getenv( 'MULTISAFEPAY_SECURE_CODE' );
47
48
		if ( Gateway::MODE_TEST === $config->mode ) {
49
			$config->api_url = MultiSafepay::API_TEST_URL;
50
		} else {
51
			$config->api_url = MultiSafepay::API_PRODUCTION_URL;
52
		}
53
54
		// Client
55
		$client = new Client();
56
57
		$client->api_url = $config->api_url;
58
59
		// Message
60
		$merchant = new Merchant();
61
62
		$merchant->account          = $config->account_id;
63
		$merchant->site_id          = $config->site_id;
64
		$merchant->site_secure_code = $config->site_code;
65
		$merchant->notification_url = home_url();
66
		$merchant->redirect_url     = home_url();
67
		$merchant->cancel_url       = home_url();
68
		$merchant->close_window     = 'false';
69
70
		$customer = new Customer();
71
72
		$customer->locale       = get_locale();
73
		$customer->ip_address   = Server::get( 'REMOTE_ADDR', FILTER_VALIDATE_IP );
74
		$customer->forwarded_ip = Server::get( 'HTTP_X_FORWARDED_FOR', FILTER_VALIDATE_IP );
75
		$customer->first_name   = '';
76
		$customer->last_name    = '';
77
		$customer->address_1    = 'Test';
78
		$customer->address_2    = '';
79
		$customer->house_number = '1';
80
		$customer->zip_code     = '1234 AB';
81
		$customer->city         = 'Test';
82
		$customer->country      = 'Test';
83
		$customer->phone        = '';
84
		$customer->email        = get_option( 'admin_email' );
85
86
		$transaction = new Transaction();
87
88
		$transaction->id          = uniqid();
89
		$transaction->currency    = 'EUR';
90
		$transaction->amount      = 123;
91
		$transaction->description = 'Test';
92
		$transaction->var1        = '';
93
		$transaction->var2        = '';
94
		$transaction->var3        = '';
95
		$transaction->items       = '';
96
		$transaction->manual      = 'false';
97
		$transaction->gateway     = '';
98
		$transaction->days_active = '';
99
		$transaction->gateway     = Methods::IDEAL;
100
		//$transaction->gateway     = Pronamic\WordPress\Pay\Gateways\MultiSafepay\Gateways::MASTERCARD;
101
		//$transaction->gateway     = Pronamic\WordPress\Pay\Gateways\MultiSafepay\Gateways::BANK_TRANSFER;
102
103
		//$gateway_info = null;
104
		$gateway_info = new GatewayInfo();
105
106
		$gateway_info->issuer_id = '3151';
107
108
		$message = new XML\DirectTransactionRequestMessage( $merchant, $customer, $transaction, $gateway_info );
109
110
		$signature = Signature::generate( $transaction->amount, $transaction->currency, $merchant->account, $merchant->site_id, $transaction->id );
111
112
		$message->signature = $signature;
0 ignored issues
show
The property signature does not seem to exist on Pronamic\WordPress\Pay\G...ansactionRequestMessage.
Loading history...
113
114
		// Response
115
		$response = $client->start_transaction( $message );
0 ignored issues
show
$message of type Pronamic\WordPress\Pay\G...ansactionRequestMessage is incompatible with the type array expected by parameter $message of Pronamic\WordPress\Pay\G...nt::start_transaction(). ( Ignorable by Annotation )

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

115
		$response = $client->start_transaction( /** @scrutinizer ignore-type */ $message );
Loading history...
116
117
		// Expected
118
		$expected = new XML\DirectTransactionResponseMessage();
119
120
		$expected->result = 'ok';
121
122
		$expected->transaction = new Transaction();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Pronamic\WordPress\P...tiSafepay\Transaction() of type Pronamic\WordPress\Pay\G...ultiSafepay\Transaction is incompatible with the declared type Pronamic\WordPress\Pay\G...nsactionResponseMessage of property $transaction.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
123
124
		$expected->transaction->id = '554202bb33498';
125
126
		$expected->gateway_info = new GatewayInfo();
127
128
		$expected->gateway_info->issuer_id    = '3151';
129
		$expected->gateway_info->redirect_url = 'http://testpay.multisafepay.com/simulator/ideal?trxid=10447735643871196&ideal=prob&issuerid=3151&merchantReturnURL=https%3A%2F%2Ftestpay%2Emultisafepay%2Ecom%2Fdirect%2Fcomplete%2F%3Fid%3D9943038943576689';
130
		$expected->gateway_info->ext_var      = 'https://testpay.multisafepay.com/direct/complete/';
131
132
		// Assert
133
		$this->assertEquals( $expected, $response );
134
	}
135
}
136