Skip to content

Commit

Permalink
PW-614: Provide a code for errors thrown by Curl (#79)
Browse files Browse the repository at this point in the history
* PW-614: Provide a code for errors thrown by Curl

* PW-614: added empty line at the end of file

* PW-614: Updated mocktests for curl errors

* PW-614: Remove if check, since an errno is always passed
  • Loading branch information
Aleffio authored Oct 18, 2018
1 parent dc43ff5 commit d063e51
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Adyen/HttpClient/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ protected function handleCurlError($url, $errno, $message, $logger)
}
$msg .= "\n(Network error [errno $errno]: $message)";
$logger->error($msg);
throw new \Adyen\ConnectionException($msg);
throw new \Adyen\ConnectionException($msg, $errno);
}

/**
Expand Down
6 changes: 2 additions & 4 deletions tests/MockTest/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ public function testAuthoriseConnectionFailure($jsonFile, $httpStatus, $errno, $
} catch (\Exception $e) {
$this->assertInstanceOf('Adyen\ConnectionException', $e);
$this->assertContains($expectedExceptionMessage, $e->getMessage());
if ($httpStatus != null) {
$this->assertEquals($httpStatus, $e->getCode());
}
$this->assertEquals($errno, $e->getCode());
}
}

Expand Down Expand Up @@ -173,4 +171,4 @@ public static function resultFailureAuthoriseProvider()
array('tests/Resources/Payment/invalid-merchant-account.json', 403, "Invalid Merchant Account")
);
}
}
}
66 changes: 65 additions & 1 deletion tests/PosPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,68 @@ public function testCreatePosEMVRefundSuccess()

}

}
/**
* After timeout, an Exception will be returned with code: CURLE_OPERATION_TIMEOUTED
* @covers \Adyen\HttpClient\CurlClient::handleCurlError
*/
public function testPosPaymentFailTimeout()
{
// initialize client
$client = $this->createTerminalCloudAPIClient();
$client->setTimeout(1);

// initialize service
$service = new Service\PosPayment($client);

//Construct request
$transactionType = \Adyen\TransactionType::NORMAL;
$serviceID = date("dHis");
$timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00");

$json = '{
"SaleToPOIRequest": {
"MessageHeader": {
"MessageType": "Request",
"MessageClass": "Service",
"MessageCategory": "Payment",
"SaleID": "PosTestLibrary",
"POIID": "' . $this->getPOIID() . '",
"ProtocolVersion": "3.0",
"ServiceID": "' . $serviceID . '"
},
"PaymentRequest": {
"SaleData": {
"SaleTransactionID": {
"TransactionID": "POStimeout",
"TimeStamp": "' . $timeStamper . '"
},
"TokenRequestedType": "Customer",
"SaleReferenceID": "SalesRefABC"
},
"PaymentTransaction": {
"AmountsReq": {
"Currency": "EUR",
"RequestedAmount": ' . 14.91 . '
}
},
"PaymentData": {
"PaymentType": "' . $transactionType . '"
}
}
}
}
';

$params = json_decode($json, true); //Create associative array for passing along

try {
$result = $service->runTenderSync($params);
$this->fail();
} catch (\Exception $e) {
$this->assertEquals(CURLE_OPERATION_TIMEOUTED, $e->getCode());
$this->validateApiPermission($e);
}

}

}

0 comments on commit d063e51

Please sign in to comment.