Skip to content

Commit

Permalink
fix(ATL-1383): Fix intention endpoint call (#11)
Browse files Browse the repository at this point in the history
* feat(ATL-1383): Add payment intention key

* fix(ATL-1383): Fix intention endpoint call
  • Loading branch information
NadaHamada authored Oct 30, 2024
1 parent 5f7b2a0 commit 269fb13
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/Paymob.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class Paymob
*
* @var string
*/
private $api = 'https://accept.paymob.com/api/';
private $api = 'https://accept.paymob.com/';

private $response;

Expand All @@ -50,7 +50,7 @@ public function createOrder(PaymentOrder $order): Paymob
{

$response = Http::withHeaders(['Content-Type' => 'application/json'])
->post($this->api . 'ecommerce/orders', [
->post($this->api . 'api/ecommerce/orders', [
'auth_token' => $this->authToken,
'delivery_needed' => $order->deliveryNeeded,
'amount_cents' => $order->amount,
Expand Down Expand Up @@ -83,7 +83,7 @@ public function createPaymentKey(PaymentKey $paymentKey): Paymob
public function createAcceptancePaymentKey(PaymentKey $paymentKey): Paymob
{
$response = Http::withHeaders(['Content-Type' => 'application/json'])
->post($this->api . 'acceptance/payment_keys', [
->post($this->api . 'api/acceptance/payment_keys', [
'auth_token' => $this->authToken,
'amount_cents' => $paymentKey->amount,
'expiration' => $paymentKey->expiration,
Expand Down Expand Up @@ -118,7 +118,7 @@ public function createIntentionPaymentKey(PaymentKey $paymentKey): Paymob
$response = Http::withHeaders([
'Authorization' => 'Token ' . $paymentKey->secretKey,
'Content-Type' => 'application/json',
])->post($this->api . 'v1/intention/', [
])->post($this->api . '/v1/intention/', [
'amount' => $paymentKey->amount,
'currency' => $paymentKey->currency,
'payment_methods' => [$paymentKey->motoIntegrationId],
Expand Down Expand Up @@ -152,7 +152,7 @@ public function payWithSavedToken(string $cardToken): Paymob
try {
$response = Http::timeout(16)
->withHeaders(['Content-Type' => 'application/json'])
->post($this->api . 'acceptance/payments/pay', [
->post($this->api . 'api/acceptance/payments/pay', [
'source' => [
'identifier' => $cardToken,
'subtype' => 'TOKEN',
Expand All @@ -171,7 +171,7 @@ public function payWithSavedToken(string $cardToken): Paymob
public function syncTransactionResponse($uuid)
{
$response = Http::withHeaders(['Content-Type' => 'application/json'])
->post($this->api . 'ecommerce/orders/transaction_inquiry', [
->post($this->api . 'api/ecommerce/orders/transaction_inquiry', [
'merchant_order_id' => $uuid,
'auth_token' => $this->authToken,
]);
Expand All @@ -183,7 +183,7 @@ public function syncTransactionResponse($uuid)
public function refund(array $data)
{
$response = Http::withHeaders(['Content-Type' => 'application/json'])
->post($this->api . 'acceptance/void_refund/refund', [
->post($this->api . 'api/acceptance/void_refund/refund', [
'auth_token' => $this->authToken,
'amount_cents' => $data['amount'],
'transaction_id' => $data['transaction_id'],
Expand All @@ -197,7 +197,7 @@ public function refund(array $data)
public function voidRefund(string $transactionId)
{
$response = Http::withHeaders(['Content-Type' => 'application/json'])
->post($this->api . 'acceptance/void_refund/void?token=' . $this->authToken, [
->post($this->api . 'api/acceptance/void_refund/void?token=' . $this->authToken, [
'transaction_id' => $transactionId,
]);

Expand All @@ -212,7 +212,7 @@ public function response()
private function authenticate(string $apiKey): void
{
$response = Http::withHeaders(['Content-Type' => 'application/json',])
->post($this->api . 'auth/tokens', ['api_key' => $apiKey]);
->post($this->api . 'api/auth/tokens', ['api_key' => $apiKey]);

$this->response = new AuthenticationResponse($response);
$this->authToken = $this->response->getAuthToken();
Expand Down
2 changes: 1 addition & 1 deletion src/Response/PaymentKeyResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getPaymentKeyToken(): string
*/
public function getIntentionPaymentKeyToken(): string
{
return $this->body->payment_keys['key'];
return $this->body->payment_keys[0]->key;
}

private function handleResponseExceptions(): void
Expand Down

0 comments on commit 269fb13

Please sign in to comment.