Skip to content

Commit

Permalink
Fix styles
Browse files Browse the repository at this point in the history
  • Loading branch information
omalizadeh committed Oct 23, 2023
1 parent 34ee4d9 commit 6bdfeba
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/Drivers/Paystar/Paystar.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function purchase(): string

if ($response['status'] !== $this->getSuccessResponseStatusCode()) {
$message = $response['message'] ?? $this->getStatusMessage($response['status']);

throw new PurchaseFailedException($message, $response['status'], $purchaseData);
}

Expand Down Expand Up @@ -61,6 +62,7 @@ public function verify(): Receipt

if ($response['status'] !== $this->getSuccessResponseStatusCode()) {
$message = $response['message'] ?? $this->getStatusMessage($response['status']);

throw new PaymentFailedException($message, $response['status']);
}

Expand All @@ -70,7 +72,7 @@ public function verify(): Receipt
$this->getInvoice(),
$response['data']['ref_num'],
null,
$response['data']['card_number']
$response['data']['card_number'],
);
}

Expand All @@ -85,7 +87,6 @@ protected function getPurchaseData(): array
throw new InvalidConfigurationException('gateway_id key has not been set.');
}


if (empty($this->settings['type'])) {
throw new InvalidConfigurationException('type key has not been set.');
}
Expand All @@ -100,10 +101,10 @@ protected function getPurchaseData(): array
throw new InvalidConfigurationException('secret_key key has not been set.');
}

$sign = hash_hmac('sha512', $this->getInvoice()->getAmount() . '#' . $this->getInvoice()->getInvoiceId() . '#' . $this->settings['callback'], $this->settings['secret_key']);
$sign = hash_hmac('sha512', $this->getInvoice()->getAmount().'#'.$this->getInvoice()->getInvoiceId().'#'.$this->settings['callback'], $this->settings['secret_key']);
}

if (!empty($mobile)) {
if (! empty($mobile)) {
$mobile = $this->checkPhoneNumberFormat($mobile);
}

Expand All @@ -116,18 +117,19 @@ protected function getPurchaseData(): array
'email' => $email ?? '',
'order_id' => $this->getInvoice()->getInvoiceId(),
'description' => $description,
'sign' => $sign ?? ''
];
} else {
return [
'amount' => $this->getInvoice()->getAmount(),
'callback' => $callback,
'mobile' => $mobile,
'email' => $email ?? '',
'order_id' => $this->getInvoice()->getInvoiceId(),
'description' => $description
'sign' => $sign ?? '',
];
}

return [
'amount' => $this->getInvoice()->getAmount(),
'callback' => $callback,
'mobile' => $mobile,
'email' => $email ?? '',
'order_id' => $this->getInvoice()->getInvoiceId(),
'description' => $description,
];

}

/**
Expand All @@ -142,22 +144,21 @@ protected function getVerificationData(): array
throw new InvalidConfigurationException('secret_key key has not been set.');
}

$sign = hash_hmac('sha512', $this->getInvoice()->getAmount() . '#' . $this->getInvoice()->getTransactionId() . '#' . $cartNumber . '#' . $trackingCode, $this->settings['secret_key']);
$sign = hash_hmac('sha512', $this->getInvoice()->getAmount().'#'.$this->getInvoice()->getTransactionId().'#'.$cartNumber.'#'.$trackingCode, $this->settings['secret_key']);
}

if ($this->settings['use_sign']) {
return [
'ref_num' => $this->getInvoice()->getTransactionId(),
'amount' => $this->getInvoice()->getAmount(),
'sign' => $sign ?? ''
];
} else {
return [
'ref_num' => $this->getInvoice()->getTransactionId(),
'amount' => $this->getInvoice()->getAmount(),
'sign' => $sign ?? '',
];
}

return [
'ref_num' => $this->getInvoice()->getTransactionId(),
'amount' => $this->getInvoice()->getAmount(),
];

}

Expand Down Expand Up @@ -197,17 +198,17 @@ protected function getSuccessResponseStatusCode(): int

protected function getPurchaseUrl(): string
{
return 'https://core.paystar.ir/api/' . $this->settings['type'] . '/create';
return 'https://core.paystar.ir/api/'.$this->settings['type'].'/create';
}

protected function getPaymentUrl(): string
{
return 'https://core.paystar.ir/api/' . $this->settings['type'] . '/payment';
return 'https://core.paystar.ir/api/'.$this->settings['type'].'/payment';
}

protected function getVerificationUrl(): string
{
return 'https://core.paystar.ir/api/' . $this->settings['type'] . '/verify';
return 'https://core.paystar.ir/api/'.$this->settings['type'].'/verify';
}

private function getRequestHeaders(): array
Expand All @@ -229,6 +230,7 @@ private function callApi(string $url, array $data)
if ($response->successful()) {
return $response->json();
}

throw new HttpRequestFailedException($response->body(), $response->status());
}

Expand All @@ -239,7 +241,7 @@ private function checkPhoneNumberFormat(string $phoneNumber): string
}

if (strlen($phoneNumber) === 10 && Str::startsWith($phoneNumber, '9')) {
return '0' . $phoneNumber;
return '0'.$phoneNumber;
}

return $phoneNumber;
Expand Down

0 comments on commit 6bdfeba

Please sign in to comment.