globalpayments / php-sdk

GNU General Public License v2.0
46 stars 67 forks source link

Refund Migration to PHP-SDK #124

Open betohorta-mf opened 3 months ago

betohorta-mf commented 3 months ago

Hello team,

I am doing the migration to the new library and I am having dificulty with the refund. This is the refund logic that I was using with the old library.

` use com\realexpayments\remote\sdk\RealexClient; use com\realexpayments\remote\sdk\domain\payment\PaymentRequest; use com\realexpayments\remote\sdk\domain\payment\PaymentType; use com\realexpayments\remote\sdk\http\HttpConfiguration; use com\realexpayments\remote\sdk\RealexServerException;

$request = ( new PaymentRequest() ) ->addType(PaymentType::PAYMENT_OUT) ->addMerchantId("merchant") ->addAccount( "account") ->addAmount(1900) ->addOrderId("order_id_goes_here") ->addCurrency("EUR") ->addPayerReference("payer_unique_id_goes_here") ->addPaymentMethod("card_ref_unique_id_goes_here") ->addRefundHash(sha1("refund_password"));

$httpConfiguration = new HttpConfiguration(); $httpConfiguration->setEndpoint("https://api.sandbox.realexpayments.com/epage-remote.cgi"); $client = new RealexClient("secret", $httpConfiguration);

try { $paymentResponse = $client->send($request); }catch (RealexServerException $e) { echo $e->getMessage(); } `

How do I convert this code to PHP-SDK library?

Thank you in advance.

CristinaNechitaGP commented 3 months ago

Hello,

Sorry for the late reply. `use GlobalPayments\Api\ServiceConfigs\Gateways\GpEcomConfig; use GlobalPayments\Api\ServicesContainer; use GlobalPayments\Api\PaymentMethods\RecurringPaymentMethod; use GlobalPayments\Api\Entities\Exceptions\ApiException;

$config = new GpEcomConfig(); $config->merchantId = 'merchant'; $config->accountId = 'account'; $config->refundPassword = 'refund_password'; $config->sharedSecret = 'secret'; ServicesContainer::configureService($config);

$paymentMethod = new RecurringPaymentMethod('payer_unique_id_goes_here', 'card_ref_unique_id_goes_here'); try { $response = $paymentMethod->refund(1900) ->withCurrency("EUR") ->withOrderId('order_id_goes_here') ->execute(); } catch (ApiException $e) { // TODO: Add your error handling here } if (isset($response)) { $result = $response->responseCode; // 00 == Success $message = $response->responseMessage; // [ test system ] AUTHORISED $orderId = $response->orderId; $authCode = $response->authorizationCode; $paymentsReference = $response->transactionId; $schemeReferenceData = $response->schemeId; }`

Also you can find more details and sample codes here https://developer.globalpay.com/ecommerce/card-storage#api . Hope this helps.