mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Working on Authorize Refunds
This commit is contained in:
parent
889ac65f26
commit
7e73aa85cb
@ -50,15 +50,15 @@ class AuthorizeTransactions
|
||||
|
||||
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok"))
|
||||
{
|
||||
echo "SUCCESS: Transaction Status:" . $response->getTransaction()->getTransactionStatus() . "\n";
|
||||
echo " Auth Amount:" . $response->getTransaction()->getAuthAmount() . "\n";
|
||||
echo " Trans ID:" . $response->getTransaction()->getTransId() . "\n";
|
||||
info( "SUCCESS: Transaction Status:" . $response->getTransaction()->getTransactionStatus() );
|
||||
info( " Auth Amount:" . $response->getTransaction()->getAuthAmount() );
|
||||
info( " Trans ID:" . $response->getTransaction()->getTransId() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "ERROR : Invalid response\n";
|
||||
info( "ERROR : Invalid response\n");
|
||||
$errorMessages = $response->getMessages()->getMessage();
|
||||
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
|
||||
info( "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() );
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
@ -12,7 +12,9 @@
|
||||
|
||||
namespace App\PaymentDrivers\Authorize;
|
||||
|
||||
use App\Models\Payment;
|
||||
use App\PaymentDrivers\AuthorizePaymentDriver;
|
||||
use App\PaymentDrivers\Authorize\AuthorizeTransactions;
|
||||
use net\authorize\api\contract\v1\CreateTransactionRequest;
|
||||
use net\authorize\api\contract\v1\CustomerProfilePaymentType;
|
||||
use net\authorize\api\contract\v1\PaymentProfileType;
|
||||
@ -26,15 +28,23 @@ use net\authorize\api\controller\CreateTransactionController;
|
||||
*/
|
||||
class RefundTransaction
|
||||
{
|
||||
public $authorize;
|
||||
|
||||
public function __construct(AuthorizePaymentDriver $authorize)
|
||||
public $authorize_transaction;
|
||||
|
||||
public function __construct(AuthorizePaymentDriver $authorize, AuthorizeTransactions $authorize_transaction)
|
||||
{
|
||||
$this->authorize = $authorize;
|
||||
$this->authorize_transaction = new AuthorizeTransactions($this->authorize);
|
||||
}
|
||||
|
||||
function refundTransaction($transaction_reference, $amount, $payment_profile_id, $profile_id)
|
||||
function refundTransaction(Payment $payment, $amount)
|
||||
{
|
||||
|
||||
$transaction_details = $this->authorize_transaction->getTransactionDetails($payment->transaction_reference);
|
||||
|
||||
info(print_r($transaction_details,1));
|
||||
|
||||
$this->authorize->init();
|
||||
|
||||
// Set the transaction's refId
|
||||
@ -53,7 +63,7 @@ class RefundTransaction
|
||||
$transactionRequest->setTransactionType("refundTransaction");
|
||||
$transactionRequest->setAmount($amount);
|
||||
$transactionRequest->setProfile($customerProfile);
|
||||
$transactionRequest->setRefTransId($transaction_reference);
|
||||
$transactionRequest->setRefTransId($payment->transaction_reference);
|
||||
|
||||
$request = new CreateTransactionRequest();
|
||||
$request->setMerchantAuthentication($this->authorize->merchant_authentication);
|
||||
@ -68,20 +78,32 @@ class RefundTransaction
|
||||
{
|
||||
$tresponse = $response->getTransactionResponse();
|
||||
|
||||
if ($tresponse != null && $tresponse->getMessages() != null)
|
||||
if ($tresponse != null && $tresponse->getMessages() != null)
|
||||
{
|
||||
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
|
||||
echo "Refund SUCCESS: " . $tresponse->getTransId() . "\n";
|
||||
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
|
||||
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
|
||||
|
||||
return [
|
||||
'transaction_reference' => $tresponse->getTransId(),
|
||||
'success' => true,
|
||||
'description' => $tresponse->getMessages()[0]->getDescription(),
|
||||
'code' => $tresponse->getMessages()[0]->getCode(),
|
||||
'transaction_response' => $tresponse->getResponseCode()
|
||||
];
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Transaction Failed \n";
|
||||
|
||||
if($tresponse->getErrors() != null)
|
||||
{
|
||||
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
|
||||
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
|
||||
|
||||
return [
|
||||
'transaction_reference' => '',
|
||||
'transaction_response' => '',
|
||||
'success' => false,
|
||||
'description' => $tresponse->getErrors()[0]->getErrorText(),
|
||||
'code' => $tresponse->getErrors()[0]->getErrorCode(),
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,22 +113,50 @@ class RefundTransaction
|
||||
$tresponse = $response->getTransactionResponse();
|
||||
if($tresponse != null && $tresponse->getErrors() != null)
|
||||
{
|
||||
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
|
||||
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
|
||||
|
||||
return [
|
||||
'transaction_reference' => '',
|
||||
'transaction_response' => '',
|
||||
'success' => false,
|
||||
'description' => $tresponse->getErrors()[0]->getErrorText(),
|
||||
'code' => $tresponse->getErrors()[0]->getErrorCode(),
|
||||
];
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
|
||||
echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
|
||||
|
||||
return [
|
||||
'transaction_reference' => '',
|
||||
'transaction_response' => '',
|
||||
'success' => false,
|
||||
'description' => $response->getMessages()->getMessage()[0]->getText(),
|
||||
'code' => $response->getMessages()->getMessage()[0]->getCode(),
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "No response returned \n";
|
||||
|
||||
return [
|
||||
'transaction_reference' => '',
|
||||
'transaction_response' => '',
|
||||
'success' => false,
|
||||
'description' => 'No response returned',
|
||||
'code' => 'No response returned',
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
return $response;
|
||||
return [
|
||||
'transaction_reference' => '',
|
||||
'transaction_response' => '',
|
||||
'success' => false,
|
||||
'description' => 'No response returned',
|
||||
'code' => 'No response returned',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,6 +14,7 @@ namespace App\PaymentDrivers;
|
||||
|
||||
use App\Models\ClientGatewayToken;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\Payment;
|
||||
use App\PaymentDrivers\Authorize\AuthorizeCreditCard;
|
||||
use App\PaymentDrivers\Authorize\AuthorizePaymentMethod;
|
||||
use net\authorize\api\constants\ANetEnvironment;
|
||||
@ -127,7 +128,7 @@ class AuthorizePaymentDriver extends BaseDriver
|
||||
return false;
|
||||
}
|
||||
|
||||
public function refund($amount, $transaction_reference, $return_client_response = false)
|
||||
public function refund(Payment $payment, $refund_amount, $return_client_response = false)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -82,12 +82,12 @@ class BaseDriver extends AbstractPaymentDriver
|
||||
/**
|
||||
* Executes a refund attempt for a given amount with a transaction_reference
|
||||
*
|
||||
* @param Payment $payment The Payment Object
|
||||
* @param float $amount The amount to be refunded
|
||||
* @param string $transaction_reference The transaction reference
|
||||
* @param boolean $return_client_response Whether the method needs to return a response (otherwise we assume an unattended payment)
|
||||
* @return mixed
|
||||
*/
|
||||
public function refund($amount, $transaction_reference, $return_client_response = false) {}
|
||||
public function refund(Payment $payment, $amount, $return_client_response = false) {}
|
||||
|
||||
/**
|
||||
* Set the inbound request payment method type for access.
|
||||
|
@ -2,6 +2,10 @@
|
||||
|
||||
namespace Tests\Integration\PaymentDrivers;
|
||||
|
||||
use App\Factory\PaymentFactory;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\PaymentDrivers\AuthorizePaymentDriver;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
use net\authorize\api\constants\ANetEnvironment;
|
||||
use net\authorize\api\contract\v1 as AnetAPI;
|
||||
@ -31,6 +35,7 @@ use net\authorize\api\controller\GetMerchantDetailsController;
|
||||
*/
|
||||
class AuthorizeTest extends TestCase
|
||||
{
|
||||
use MockAccountData;
|
||||
|
||||
public $customer_profile_id = 1512191314;
|
||||
|
||||
@ -43,7 +48,8 @@ class AuthorizeTest extends TestCase
|
||||
if (! config('ninja.testvars.authorize')) {
|
||||
$this->markTestSkipped('authorize.net not configured');
|
||||
}
|
||||
|
||||
|
||||
$this->makeTestData();
|
||||
}
|
||||
|
||||
public function testUnpackingVars()
|
||||
@ -372,6 +378,27 @@ class AuthorizeTest extends TestCase
|
||||
}
|
||||
|
||||
$this->assertNotNull($response);
|
||||
|
||||
$this->assertNotNull($tresponse);
|
||||
|
||||
//$tresponse->getTransId()
|
||||
|
||||
$payment = PaymentFactory::create($this->company->id, $this->user->id);
|
||||
$payment->amount = 400;
|
||||
$payment->client_id = $this->client->id;
|
||||
$payment->date = now();
|
||||
$payment->transaction_reference = $tresponse->getTransId();
|
||||
$payment->save();
|
||||
|
||||
$company_gateway = CompanyGateway::where('gateway_key', '3b6621f970ab18887c4f6dca78d3f8bb')->first();
|
||||
|
||||
$authorize_payment_driver = new AuthorizePaymentDriver($company_gateway, $this->client);
|
||||
$response = $authorize->refund($payment, 400);
|
||||
|
||||
info(print_r($response,1));
|
||||
|
||||
$this->assertTrue(is_array($response));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user