簡體   English   中英

使用 PayPal 快速結賬的 Omnipay

[英]Omnipay with PayPal express checkout

我想將 PayPal Express Checkout 與 Omnipay 集成,但文檔完全未完成。 如何運行“setExpressCheckout”、“doExpressCheckout”和“getExpressCheckout”等方法? 另外,如何將所有 PayPal 調用重定向到 IPN 偵聽器? Omnipay 提供所有這些方法還是僅提供其中的一部分? 有沒有人有機會在 Express Checkout 中使用這個庫?

問候!

這不是答案,但首先讓我建議您從 PayPal Express 切換到 PayPal REST,因為后者有更好的文檔記錄和更新的界面。

實際答案:Omnipay 不是這樣工作的。 它不直接公開底層網關方法,像“setExpressCheckout”、“doExpressCheckout”和“getExpressCheckout”這樣的方法是 PayPal 方法而不是 Omnipay 方法。 取而代之的是與網關無關的方法,例如purchase() 和refund() 等。

因此,對於 omnipay-paypal REST 網關文檔的示例(作為類標題中的文檔塊),您需要執行以下操作:

// Create a gateway for the PayPal RestGateway
// (routes to GatewayFactory::create)
$gateway = Omnipay::create('PayPal_Rest');

// Initialise the gateway
$gateway->initialize(array(
    'clientId' => 'MyPayPalClientId',
    'secret'   => 'MyPayPalSecret',
    'testMode' => true, // Or false when you are ready for live transactions
));

那只是為了初始化網關。 除了您使用 PayPal_Express 作為網關名稱並且initialize()參數不同之外,該過程與 PayPal express 相同

然后進行購買,例如,如果您被允許使用卡號進行購買:

// Create a credit card object
// DO NOT USE THESE CARD VALUES -- substitute your own
// see the documentation in the class header.
$card = new CreditCard(array(
            'firstName' => 'Example',
            'lastName' => 'User',
            'number' => '4111111111111111',
            'expiryMonth'           => '01',
            'expiryYear'            => '2020',
            'cvv'                   => '123',
            'billingAddress1'       => '1 Scrubby Creek Road',
            'billingCountry'        => 'AU',
            'billingCity'           => 'Scrubby Creek',
            'billingPostcode'       => '4999',
            'billingState'          => 'QLD',
));

// Do a purchase transaction on the gateway
try {
    $transaction = $gateway->purchase(array(
        'amount'        => '10.00',
        'currency'      => 'AUD',
        'description'   => 'This is a test purchase transaction.',
        'card'          => $card,
    ));
    $response = $transaction->send();
    $data = $response->getData();
    echo "Gateway purchase response data == " . print_r($data, true) . "\n";

    if ($response->isSuccessful()) {
        echo "Purchase transaction was successful!\n";
    }
} catch (\Exception $e) {
    echo "Exception caught while attempting authorize.\n";
    echo "Exception type == " . get_class($e) . "\n";
    echo "Message == " . $e->getMessage() . "\n";
}

執行重定向付款(例如 PayPal 帳戶付款)有些不同,但它記錄在類文檔塊中。 見 src/Messages/RestPurchaseRequest.php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM