我想将PayPal Express Checkout与Omnipay集成,但文档完全未完成。如何运行类似' setExpressCheckout',' doExpressCheckout'和' getExpressCheckout'?另外,如何将所有PayPal调用重定向到IPN侦听器? Omnipay是否提供所有这些方法或仅提供其中的一部分?有没有人有机会在Express Checkout上使用这个库?
问候!
答案 0 :(得分:1)
这不是一个答案,但首先让我建议您从PayPal Express切换到PayPal REST,因为后者有更好的文档和更新的界面。
实际答案:Omnipay不能那样工作。它没有直接暴露底层网关方法,像'setExpressCheckout','doExpressCheckout'和'getExpressCheckout'这样的方法是PayPal方法而不是Omnipay方法。取而代之的是与网关无关的方法,例如purchase()和refund()等。
因此,对于omnipay-paypal REST网关文档的示例(作为类标题中的docblock),您可以执行以下操作:
// 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作为网关名称之外,PayPal Express的流程相同,您可以使用initialize()
然后进行购买,例如如果您被允许这样做,请使用卡号:
// 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