Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refund Migration to PHP-SDK #124

Open
betohorta-mf opened this issue Mar 22, 2024 · 1 comment
Open

Refund Migration to PHP-SDK #124

betohorta-mf opened this issue Mar 22, 2024 · 1 comment

Comments

@betohorta-mf
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants