Merge "Fixed and catch stripes errors on refund"

This commit is contained in:
Zuul 2019-06-27 16:20:15 +00:00 committed by Gerrit Code Review
commit 61eab29443
3 changed files with 44 additions and 2 deletions

View File

@ -162,6 +162,8 @@ final class StripeApi implements IPaymentGatewayAPI
if(is_null($intent))
throw new \InvalidArgumentException();
if(count($intent->charges->data) == 0)
throw new \InvalidArgumentException("this intent payment has no charges");
$charge = $intent->charges->data[0];
if(!$charge instanceof Charge)
throw new \InvalidArgumentException();

View File

@ -1827,11 +1827,19 @@ final class SummitLocationService
if ($reservation->getStatus() == SummitRoomReservation::ReservedStatus)
throw new ValidationException("can not request a refund on a reserved booking!");
if($amount <= 0){
throw new ValidationException("can not refund an amount lower than zero!");
}
if($amount > intval($reservation->getAmount())){
throw new ValidationException("can mot refund an amount greater than paid one!");
throw new ValidationException("can not refund an amount greater than paid one!");
}
try{
$this->payment_gateway->refundPayment($reservation->getPaymentGatewayCartId(), $amount);
}
catch (\Exception $ex){
throw new ValidationException($ex->getMessage());
}
$reservation->refund($amount);

32
tests/StripeTest.php Normal file
View File

@ -0,0 +1,32 @@
<?php namespace Tests;
/**
* Copyright 2019 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Services\Apis\PaymentGateways\StripeApi;
use Illuminate\Support\Facades\Config;
/**
* Class StripeTest
* @package Tests
*/
final class StripeTest extends TestCase
{
public function testRefund(){
$api = new StripeApi(
Config::get("stripe.private_key", null),
Config::get("stripe.endpoint_secret", null)
);
$api->refundPayment("pi_1Epa7kL4yik3a08Jlf8SN6YS", 30);
}
}