Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PW-614: Provide a code for errors thrown by Curl #79

Merged
merged 4 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}

}