Omnipay迁移整合

时间:2016-01-05 13:21:24

标签: php omnipay

您好我在我的项目中使用omnipay github lib和migs集成。示例代码似乎不起作用。任何人都可以帮我这个吗?

require_once 'vendor/autoload.php';

use \Omnipay\Omnipay as omnipay;

$gateway = Omnipay::create('Migs_ThreeParty');
$gateway->setMerchantId('foo');
$gateway->setMerchantAccessCode('foo');
$gateway->setSecureHash('foo');

try {
    $response = $gateway->purchase(array('amount' => '0.00', 'currency' => 'AED', 'returnURL' => 'www.google.com.pk'))->send();

    if ($response->isRedirect()) {
        // redirect to offsite payment gateway
        $response->redirect();
        //$url = $response->getRedirectUrl();
        //$data = $response->getRedirectData();

    } else {
        // payment failed: display message to customer
        echo $response->getMessage();
    }
} catch (\Exception $e) {
    // internal error, log exception and display a generic message to the customer
    exit('Sorry, there was an error processing your payment. Please try again later.');
}

" $ gateway-> setSecureHash" ==" $ SECURE_SECRET"如示例链接http://integrate-payment-gateway.blogspot.in/2012/01/migs-payment-gateway-integration-php.html

所示

以上代码要求redirectUrl和transactionId。在哪里指定它?

1 个答案:

答案 0 :(得分:0)

require_once 'vendor/autoload.php';

use \Omnipay\Omnipay as omnipay;

$gateway = Omnipay::create('Migs_ThreeParty');
$gateway->setMerchantId('MerchantId');
$gateway->setMerchantAccessCode('MerchantAccessCode');
$gateway->setSecureHash('SecureHash');

try {
    $response = $gateway->purchase(array(
        'amount' => '10.00', // amount should be greater than zero
        'currency' => 'AED',
        'transactionId' => 'refnodata', // replace this for your reference # such as invoice reference #
        'returnURL' => 'http://yourdomain.com/returnPage.php'))->send();

    if ($response->isRedirect()) {
        $url = $response->getRedirectUrl(); // do whatever with the return url
    } else {
        // payment failed: display message to customer
        echo $response->getMessage();
    }
} catch (\Exception $e) {
    // internal error, log exception and display a generic message to the customer
    echo $e;
    exit('Sorry, there was an error processing your payment. Please try again later.');
}