Recurring payment integration with Realex/Global payment

1.2k Views Asked by At

I am trying to create a recurring payment for Global payment gateway. But getting below error -

The selected gateway does not support this transaction type.

$config = new ServicesConfig();
$config->merchantId = "MerchantId";
$config->accountId = "AccountId";
$config->sharedSecret = "SharedSecret";
$config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay";
$config->hostedPaymentConfig = new HostedPaymentConfig();
$config->hostedPaymentConfig->version = HppVersion::VERSION_2;
if ($recurring){
    $config->hostedPaymentConfig->cardStorageEnabled = "1";
}
$service = new HostedService(
    $config
);

$hostedPaymentData = new HostedPaymentData();
$hostedPaymentData->offerToSaveCard = true; // display the save card tick box
$hostedPaymentData->customerExists = false; // new customer
echo $service->Authorize($amount)
    ->withCurrency($currency_code)
    ->withRecurringInfo(RecurringType::FIXED, RecurringSequence::FIRST)
    ->withOrderId($order_id) 
    ->withHostedPaymentData($hostedPaymentData)
    ->serialize();

On server side I am getting POST response from payment gateway with customer id and payment id.

$parsedResponse = $service->parseResponse(json_encode($_POST));
$responseValues  = $parsedResponse->responseValues; // get values accessible by key
$schedule = createSchedule($responseValues);


function createSchedule($responseValues)
{
    $schedule = new Schedule();

    $customerKey = $responseValues['SAVED_PAYER_REF'];
    $paymentMethodKey = $responseValues['SAVED_PMT_REF'];
    $orderId = $responseValues['ORDER_ID'];
    $amount = $responseValues['AMOUNT'];

    $schedule->id               = getIdentifier('CreditV');
    $schedule->customerKey      = $customerKey;
    $schedule->paymentKey       = $paymentMethodKey;
    $schedule->amount           = $amount;//$_REQUEST['a3'] * 100;
    $schedule->currency         = 'EUR';//$_REQUEST['cc']
    $schedule->startDate        = date('mdY'); //, strtotime("last day of next month")
    $schedule->paymentSchedule  = PaymentSchedule::DYNAMIC; //or PaymentSchedule::FIRST_DAY_OF_THE_MONTH
    $schedule->frequency        = ScheduleFrequency::WEEKLY; //'Monthly', 'Bi-Monthly', 'Quarterly', 'Semi-Annually'
    $schedule->numberOfPayments = 4;
    $schedule->description      = 'Test';
    $schedule->poNumber         = $orderId;
    $schedule->reprocessingCount = 1;
    $schedule->emailReceipt      = 'Never';
    $schedule->status            = 'Active';
    $response = $schedule->create();

    return $response;
}

function getIdentifier($id)
{
    $identifierBase = '%s-%s' . substr(str_shuffle('abcdefghijklmnopqrstuvwxyz'), 0, 10);
    return sprintf($identifierBase, date('Ymd'), $id);
}
1

There are 1 best solutions below

4
Global Payments On

Thanks for your question. Unfortunately, the Global Payments SDK right now does not support the creation of scheduled payments with the Global Payments Ecommerce solution. It does work with the Heartland gateway but that is a separate product that is currently US only.

If you are string cards with the Hosted Payments Page, you can setup schedules against them using our XML API: https://developer.globalpay.com/#!/api/payment-scheduler