Reputation: 9722
Since my attempt at using the PayPal REST API directly failed, I'm trying to see if Omnipay is an option ... is there a way to use the REST API with Omnipay? So far the only integration I've seen requires a username
and password
, not client id
and client secret
:
$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername('XXXXX');
$gateway->setPassword('XXXX');
$gateway->setSignature('XXXXX');
$response = $gateway->completePurchase(
array(
'cancelUrl' => 'www.xyz.com/cancelurl',
'returnUrl' => 'www.xyz.com/returnurl',
'amount' => '25.00',
'currency' => 'CAD'
)
)->send();
Upvotes: 2
Views: 6360
Reputation: 3790
For anyone else who found this post, there is support for REST API.
An excerpt from RestGateway.php
found in the source code full doc
- The PayPal REST APIs are supported in two environments. Use the Sandbox environment
- for testing purposes, then move to the live environment for production processing.
- When testing, generate an access token with your test credentials to make calls to
- the Sandbox URIs. When you’re set to go live, use the live credentials assigned to
- your app to generate a new access token to be used with the live URIs.
commit https://github.com/thephpleague/omnipay-paypal/pull/21
// Create a gateway for the PayPal RestGateway
// (routes to GatewayFactory::create)
$gateway = Omnipay::create('RestGateway');
// Initialise the gateway
$gateway->initialize(array(
'clientId' => 'MyPayPalClientId',
'secret' => 'MyPayPalSecret',
'testMode' => true, // Or false when you are ready for live transactions
));
// 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 an authorisation transaction on the gateway
$transaction = $gateway->authorize(array(
'amount' => '10.00',
'currency' => 'AUD',
'description' => 'This is a test authorize transaction.',
'card' => $card,
));
$response = $transaction->send();
if ($response->isSuccessful()) {
echo "Authorize transaction was successful!\n";
// Find the authorization ID
$auth_id = $response->getTransactionReference();
}
from RestAuthorizeRequest.php
Upvotes: 3
Reputation: 13263
No, Omnipay doesn't support the REST API yet.
That said, Omnipay abstracts the differences between various APIs, so it doesn't really matter to you which API you are using. The code you posted above should work fine with PayPal Express Checkout, so just make sure you are using the correct API keys and it will all be easy.
Upvotes: 0
Reputation: 26036
The REST API is still very new at PayPal and simply isn't as complete. Not many 3rd party frameworks have implemented it yet.
It looks like you're working with PHP and trying to implement Express Checkout..?? If so, I'd recommend taking a look at my class library for PayPal. You can have that done within minutes.
It uses an API username, password, and signature as well. You can get these credentials out of your PayPal account profile under the API Access section.
My library comes with Express Checkout samples that are functional and easy to follow, and then there are empty templates you can start from to setup your own and just fill in whatever parameters you need.
Upvotes: 0