Skip to content

Commit

Permalink
Fixed building URLs for various gatewayUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
Štefan Földesi committed May 17, 2023
1 parent 42b2aba commit 6afce8d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
10 changes: 5 additions & 5 deletions src/GoPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getConfig($key)

public function call($urlPath, $contentType, $authorization, $method, $data = null)
{
$r = new Request($this->buildUrl("/{$urlPath}"));
$r = new Request($this->buildUrl($urlPath));
$r->method = $method;
$r->headers = $this->buildHeaders($contentType, $authorization);
$r->body = $this->encodeData($contentType, $data);
Expand All @@ -48,9 +48,9 @@ public function buildUrl($urlPath)
];

if ($this->isCustomGatewayUrl()) {
$apiRoot = $this->config['gatewayUrl'];
$apiRoot = rtrim($this->config['gatewayUrl'], '/');
if (!$this->strEndsWith($apiRoot, 'api')) {
$apiRoot = $apiRoot . 'api';
$apiRoot = $apiRoot . '/api';
}
return $apiRoot . $urlPath;
}
Expand All @@ -70,10 +70,10 @@ public function buildEmbedUrl()
if ($this->strEndsWith($urlBase, 'api')) {
$urlBase = substr($urlBase, 0, -3);
}
return $urlBase . 'gp-gw/js/embed.js';
return $urlBase . '/gp-gw/js/embed.js';
}

return $urls[$this->isProductionMode()] . 'gp-gw/js/embed.js';
return $urls[$this->isProductionMode()] . '/gp-gw/js/embed.js';
}


Expand Down
2 changes: 1 addition & 1 deletion src/OAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function authorize()
{
$credentials = "{$this->gopay->getConfig('clientId')}:{$this->gopay->getConfig('clientSecret')}";
$response = $this->gopay->call(
'oauth2/token',
'/oauth2/token',
GoPay::FORM,
'Basic ' . base64_encode($credentials),
RequestMethods::POST,
Expand Down
26 changes: 13 additions & 13 deletions src/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public function createPayment(array $rawPayment)
],
'lang' => $this->gopay->getConfig('language')
];
return $this->post('payments/payment', GoPay::JSON, $payment);
return $this->post('/payments/payment', GoPay::JSON, $payment);
}

public function getStatus($id)
{
return $this->get("payments/payment/{$id}", GoPay::FORM);
return $this->get("/payments/payment/{$id}", GoPay::FORM);
}

/** @see refundPaymentEET */
Expand All @@ -38,57 +38,57 @@ public function refundPayment($id, $data)
if (is_array($data)) {
return $this->refundPaymentEET($id, $data);
}
return $this->post("payments/payment/{$id}/refund", GoPay::FORM, ['amount' => $data]);
return $this->post("/payments/payment/{$id}/refund", GoPay::FORM, ['amount' => $data]);
}

public function refundPaymentEET($id, array $paymentData)
{
return $this->post("payments/payment/{$id}/refund", GoPay::JSON, $paymentData);
return $this->post("/payments/payment/{$id}/refund", GoPay::JSON, $paymentData);
}

public function createRecurrence($id, array $payment)
{
return $this->post("payments/payment/{$id}/create-recurrence", GoPay::JSON, $payment);
return $this->post("/payments/payment/{$id}/create-recurrence", GoPay::JSON, $payment);
}

public function voidRecurrence($id)
{
return $this->post("payments/payment/{$id}/void-recurrence", GoPay::FORM, array());
return $this->post("/payments/payment/{$id}/void-recurrence", GoPay::FORM, array());
}

public function captureAuthorization($id)
{
return $this->post("payments/payment/{$id}/capture", GoPay::FORM, array());
return $this->post("/payments/payment/{$id}/capture", GoPay::FORM, array());
}

public function captureAuthorizationPartial($id, array $capturePayment)
{
return $this->post("payments/payment/{$id}/capture", GoPay::JSON, $capturePayment);
return $this->post("/payments/payment/{$id}/capture", GoPay::JSON, $capturePayment);
}

public function voidAuthorization($id)
{
return $this->post("payments/payment/{$id}/void-authorization", GoPay::FORM, array());
return $this->post("/payments/payment/{$id}/void-authorization", GoPay::FORM, array());
}

public function getPaymentInstruments($goid, $currency)
{
return $this->get("eshops/eshop/{$goid}/payment-instruments/{$currency}", null);
return $this->get("/eshops/eshop/{$goid}/payment-instruments/{$currency}", null);
}

public function getAccountStatement(array $accountStatement)
{
return $this->post("accounts/account-statement", GoPay::JSON, $accountStatement);
return $this->post("/accounts/account-statement", GoPay::JSON, $accountStatement);
}

public function getEETReceiptByPaymentId($paymentId)
{
return $this->get("payments/payment/{$paymentId}/eet-receipts", GoPay::JSON);
return $this->get("/payments/payment/{$paymentId}/eet-receipts", GoPay::JSON);
}

public function findEETReceiptsByFilter(array $filter)
{
return $this->post("eet-receipts", GoPay::JSON, $filter);
return $this->post("/eet-receipts", GoPay::JSON, $filter);
}


Expand Down
18 changes: 8 additions & 10 deletions src/PaymentsSupercash.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function createSupercashCoupon(array $supercashCoupon)
{
$coupon = ['go_id' => $this->payments->getGopay()->getConfig('goid')] + $supercashCoupon;

return $this->payments->post('supercash/coupon', GoPay::JSON, $coupon);
return $this->payments->post('/supercash/coupon', GoPay::JSON, $coupon);
}


Expand All @@ -41,7 +41,7 @@ public function createSupercashCouponBatch(array $supercashCouponBatch)
{
$batch = ["go_id" => $this->payments->getGopay()->getConfig('goid')] + $supercashCouponBatch;

return $this->payments->post("supercash/coupon/batch", GoPay::JSON, $batch);
return $this->payments->post("/supercash/coupon/batch", GoPay::JSON, $batch);
}


Expand All @@ -53,7 +53,7 @@ public function createSupercashCouponBatch(array $supercashCouponBatch)
*/
public function getSupercashCouponBatchStatus($batchId)
{
return $this->payments->get("batch/" . $batchId, GoPay::FORM);
return $this->payments->get('/batch/' . $batchId, GoPay::FORM);
}


Expand All @@ -65,8 +65,8 @@ public function getSupercashCouponBatchStatus($batchId)
*/
public function getSupercashCouponBatch($batchId)
{
return $this->payments->get("supercash/coupon/find?batch_request_id=" . $batchId
. "&go_id={$this->payments->getGopay()->getConfig('goid')}", GoPay::FORM);
return $this->payments->get("/supercash/coupon/find?batch_request_id=" . $batchId
. "&go_id={$this->payments->getGopay()->getConfig('goid')}", GoPay::FORM);
}


Expand All @@ -80,8 +80,8 @@ public function findSupercashCoupons($paymentSessionId)
{
$queryData = is_array($paymentSessionId) ? array_values($paymentSessionId) : [$paymentSessionId];

return $this->payments->get('supercash/coupon/find?payment_session_id_list=' . implode(",", $queryData)
. "&go_id={$this->payments->getGopay()->getConfig('goid')}", GoPay::FORM);
return $this->payments->get('/supercash/coupon/find?payment_session_id_list=' . implode(",", $queryData)
. "&go_id={$this->payments->getGopay()->getConfig('goid')}", GoPay::FORM);
}


Expand All @@ -93,8 +93,6 @@ public function findSupercashCoupons($paymentSessionId)
*/
public function getSupercashCoupon($couponId)
{
return $this->payments->get("supercash/coupon/{$couponId}", GoPay::FORM);
return $this->payments->get("/supercash/coupon/{$couponId}", GoPay::FORM);
}


}

0 comments on commit 6afce8d

Please sign in to comment.