From 57da585a598e60d941b0e5f3f87cbf02d1f74a02 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 12 Jun 2020 08:32:56 +1000 Subject: [PATCH] Add charge and refund methods to authorize --- .../Authorize/ChargePaymentProfile.php | 104 ++++++++++++++++ .../Authorize/RefundTransaction.php | 113 ++++++++++++++++++ app/PaymentDrivers/AuthorizePaymentDriver.php | 7 +- 3 files changed, 219 insertions(+), 5 deletions(-) create mode 100644 app/PaymentDrivers/Authorize/ChargePaymentProfile.php create mode 100644 app/PaymentDrivers/Authorize/RefundTransaction.php diff --git a/app/PaymentDrivers/Authorize/ChargePaymentProfile.php b/app/PaymentDrivers/Authorize/ChargePaymentProfile.php new file mode 100644 index 000000000000..8701e078ac20 --- /dev/null +++ b/app/PaymentDrivers/Authorize/ChargePaymentProfile.php @@ -0,0 +1,104 @@ +authorize = $authorize; + } + + + function chargeCustomerProfile($profile_id, $payment_profile_id, $amount) + { + + $this->authorize->init(); + + // Set the transaction's refId + $refId = 'ref' . time(); + + $profileToCharge = new CustomerProfilePaymentType(); + $profileToCharge->setCustomerProfileId($profile_id); + $paymentProfile = new PaymentProfileType(); + $paymentProfile->setPaymentProfileId($payment_profile_id); + $profileToCharge->setPaymentProfile($paymentProfile); + + $transactionRequestType = new TransactionRequestType(); + $transactionRequestType->setTransactionType("authCaptureTransaction"); + $transactionRequestType->setAmount($amount); + $transactionRequestType->setProfile($profileToCharge); + + $request = new CreateTransactionRequest(); + $request->setMerchantAuthentication($this->authorize->merchant_authentication); + $request->setRefId( $refId); + $request->setTransactionRequest( $transactionRequestType); + $controller = new CreateTransactionController($request); + $response = $controller->executeWithApiResponse($this->authorize->mode()); + + + if($response != null &&$response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Charge Customer Profile APPROVED :" . "\n"; + echo " Charge Customer Profile AUTH CODE : " . $tresponse->getAuthCode() . "\n"; + echo " Charge Customer Profile TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + 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"; + } + } + } + else + { + echo "Transaction Failed \n"; + $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"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + + } \ No newline at end of file diff --git a/app/PaymentDrivers/Authorize/RefundTransaction.php b/app/PaymentDrivers/Authorize/RefundTransaction.php new file mode 100644 index 000000000000..1b0772bdf2e7 --- /dev/null +++ b/app/PaymentDrivers/Authorize/RefundTransaction.php @@ -0,0 +1,113 @@ +authorize = $authorize; + } + + function refundTransaction($transaction_reference, $amount, $payment_profile_id, $profile_id) + { + + $this->authorize->init(); + + // Set the transaction's refId + $refId = 'ref' . time(); + + $paymentProfile = new PaymentProfileType(); + $paymentProfile->setPaymentProfileId( $payment_profile_id ); + + // set customer profile + $customerProfile = new CustomerProfilePaymentType(); + $customerProfile->setCustomerProfileId( $profile_id ); + $customerProfile->setPaymentProfile( $paymentProfile ); + + //create a transaction + $transactionRequest = new TransactionRequestType(); + $transactionRequest->setTransactionType("refundTransaction"); + $transactionRequest->setAmount($amount); + $transactionRequest->setProfile($customerProfile); + $transactionRequest->setRefTransId($transaction_reference); + + $request = new CreateTransactionRequest(); + $request->setMerchantAuthentication($this->authorize->merchant_authentication); + $request->setRefId($refId); + $request->setTransactionRequest($transactionRequest); + $controller = new CreateTransactionController($request); + $response = $controller->executeWithApiResponse($this->authorize->mode()); + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + 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"; + } + 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"; + } + } + } + else + { + echo "Transaction Failed \n"; + $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"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + else + { + echo "No response returned \n"; + } + + return $response; + } + + +} \ No newline at end of file diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php index af585d035b37..fa185bab2636 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -86,20 +86,17 @@ class AuthorizePaymentDriver extends BaseDriver public function authorizeResponseView(array $data) { - return (new AuthorizePaymentMethod($this))->authorizeResponseView($data['gateway_type_id'], $data); - } - public function authorize($payment_method) { - + return $this->authorizeView($payment_method); } public function purchase() { - + return () } public function refund()