这不是一个答案,但首先让我建议您从 PayPal Express 切换到 PayPal REST,因为后者有更好的文档记录和更新的界面。
实际答案:Omnipay 不是这样工作的。它不直接公开底层网关方法,并且像“setExpressCheckout”、“doExpressCheckout”和“getExpressCheckout”这样的方法是 PayPal 方法而不是 Omnipay 方法。取而代之的是与网关无关的方法,例如purchase() 和refund() 等。
因此,对于 omnipay-paypal REST 网关文档的示例(作为类标头中的 docblocks),您可以执行以下操作:
// 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 帐户付款)有些不同,但它记录在类 docblocks 中。见 src/Messages/RestPurchaseRequest.php