Skip to content

Commit

Permalink
Merge branch 'source-master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Message/AbstractRequest.php
#	src/Message/CompletePurchaseRequest.php
#	src/Message/PurchaseRequest.php
  • Loading branch information
lukeholder committed Jun 16, 2020
2 parents 9918a73 + 87a6bb3 commit fdd0f87
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 14 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
}
],
"require": {
"php": "^7.2",
"omnipay/common": "^3.0"
},
"require-dev": {
Expand Down
15 changes: 13 additions & 2 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,23 @@ public function setSecretKey($value)
$this->setParameter('secret_key', $value);
}

public function getRequestHeaders()
protected function sendRequest($method, $endpoint, array $data = null)
{
return [
$headers = [
'Authorization' => 'Bearer ' . $this->getSecretKey(),
'Content-Type' => 'application/json',
'Cache-Control' => 'no-cache'
];

$url = $this->baseApiEndpoint . $endpoint;
$response = $this->httpClient->request(
$method,
$url,
$headers,
json_encode($data)
);
$responseData = json_decode((string)$response->getBody(), true);

return $responseData;
}
}
4 changes: 2 additions & 2 deletions src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public function getData()
public function sendData($data)
{
try {
$response = $this->httpClient->request('GET', $this->getApiEndpoint(), $this->getRequestHeaders(), json_encode($data));
$responseData = json_decode((string)$response->getBody(), true);
$response = $this->sendRequest('GET', $this->getApiEndpoint(), json_encode($data));
} catch (\Exception $e) {

throw new InvalidRequestException($e->getMessage(), $e->getCode(), $e);
}

Expand Down
13 changes: 3 additions & 10 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,12 @@ public function getData()
$amount = $this->getAmountInteger();
$email = $this->getParameter('email');

$data = [
return [
'amount' => $amount,
'email' => $email,
'callback_url' => $this->getReturnUrl(),
'metadata' => $this->getParameter('metadata')
];

if ($reference = $this->getTransactionReference()) {
$data['reference'] = $reference;
}

return $data;
}

/**
Expand All @@ -44,13 +38,12 @@ public function getData()
public function sendData($data)
{
try {
$response = $this->httpClient->request('POST', $this->getApiEndpoint(), $this->getRequestHeaders(), json_encode($data));
$responseData = json_decode((string)$response->getBody(), true);
$response = $this->sendRequest('POST', $this->getApiEndpoint(), $data);
} catch (\Exception $e) {
throw new InvalidRequestException($e->getMessage(), $e->getCode(), $e);
}

return $this->response = new PurchaseResponse($this, $responseData);
return $this->response = new PurchaseResponse($this, $response);
}

/**
Expand Down
Empty file.
91 changes: 91 additions & 0 deletions tests/Mock/CompletePurchaseSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
HTTP/1.1 200 OK
Server: Apache
Date: Sun, 11 May 2014 21:17:31 GMT
Content-Type: application/json; charset=utf-8
Status: 200 OK

{
"status": true,
"message": "Verification successful",
"data": {
"id": 549256454,
"domain": "test",
"status": "success",
"reference": "0rujfjycxi",
"amount": 250000,
"message": null,
"gateway_response": "Successful",
"paid_at": "2020-03-10T15:13:18.000Z",
"created_at": "2020-03-10T15:13:04.000Z",
"channel": "card",
"currency": "NGN",
"ip_address": "154.113.67.70",
"metadata": {
"custom_fields": [
{
"display_name": "Mobile Number",
"variable_name": "mobile_number",
"value": "+2348012345678"
}
]
},
"log": {
"start_time": 1583853195,
"time_spent": 3,
"attempts": 1,
"errors": 0,
"success": true,
"mobile": false,
"input": [],
"history": [
{
"type": "action",
"message": "Attempted to pay with card",
"time": 3
},
{
"type": "success",
"message": "Successfully paid with card",
"time": 3
}
]
},
"fees": 13750,
"fees_split": null,
"authorization": {
"authorization_code": "AUTH_0kp93r4efq",
"bin": "408408",
"last4": "4081",
"exp_month": "12",
"exp_year": "2020",
"channel": "card",
"card_type": "visa DEBIT",
"bank": "Test Bank",
"country_code": "NG",
"brand": "visa",
"reusable": true,
"signature": "SIG_OwXBSHEXaO5yN8mT1PuM",
"account_name": null,
"receiver_bank_account_number": null,
"receiver_bank": null
},
"customer": {
"id": 11155546,
"first_name": null,
"last_name": null,
"email": "[email protected]",
"customer_code": "CUS_psk22uvulqz7cqi",
"phone": null,
"metadata": null,
"risk_action": "deny"
},
"plan": null,
"order_id": null,
"paidAt": "2020-03-10T15:13:18.000Z",
"createdAt": "2020-03-10T15:13:04.000Z",
"requested_amount": 250000,
"transaction_date": "2020-03-10T15:13:04.000Z",
"plan_object": {},
"subaccount": {}
}
}
Empty file added tests/Mock/PurchaseFailure.txt
Empty file.

0 comments on commit fdd0f87

Please sign in to comment.