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
));
#### Direct Credit Card Payment
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";
}
### Dashboard
Once you have processed some payments you can go to the PayPal sandbox site,
at https://www.sandbox.paypal.com/ and log in with the email address and password
of your PayPal sandbox business test account. You will then see the result
of those transactions on the "My recent activity" list under the My Account
tab.
Показать файл
Открыть проект
Примеры использования класса
Метод | Описание | |
---|---|---|
authorize ( array $parameters = [] ) : |
Create an authorization request. | |
cancelSubscription ( array $parameters = [] ) : Omnipay\PayPal\Message\RestCancelSubscriptionRequest | Cancel a subscription. | |
capture ( array $parameters = [] ) : Omnipay\PayPal\Message\RestCaptureRequest | Capture an authorization. | |
completePurchase ( array $parameters = [] ) : |
Completes a purchase request. | |
completeSubscription ( array $parameters = [] ) : Omnipay\PayPal\Message\RestCompleteSubscriptionRequest | Complete (execute) a subscription. | |
createCard ( array $parameters = [] ) : Omnipay\PayPal\Message\RestCreateCardRequest | Store a credit card in the vault | |
createPlan ( array $parameters = [] ) : Omnipay\PayPal\Message\RestCreatePlanRequest | Create a billing plan. | |
createRequest ( string $class, array $parameters = [] ) : |
Create Request | |
createSubscription ( array $parameters = [] ) : Omnipay\PayPal\Message\RestCreateSubscriptionRequest | Create a subscription. | |
createToken ( ) : |
Create OAuth 2.0 access token request. | |
deleteCard ( array $parameters = [] ) : Omnipay\PayPal\Message\RestDeleteCardRequest | Delete a credit card from the vault. | |
fetchPurchase ( array $parameters = [] ) : Omnipay\PayPal\Message\RestFetchPurchaseRequest | Fetch a purchase request. | |
fetchTransaction ( array $parameters = [] ) : Omnipay\PayPal\Message\RestFetchTransactionRequest | Fetch a Sale Transaction | |
getClientId ( ) : string | Get OAuth 2.0 client ID for the access token. | |
getDefaultParameters ( ) | ||
getName ( ) | ||
getSecret ( ) : string | Get OAuth 2.0 secret for the access token. | |
getToken ( boolean $createIfNeeded = true ) : string | Get OAuth 2.0 access token. | |
getTokenExpires ( ) : integer | Get OAuth 2.0 access token expiry time. | |
hasToken ( ) : boolean | Is there a bearer token and is it still valid? | |
listPurchase ( array $parameters = [] ) : Omnipay\PayPal\Message\RestListPurchaseRequest | List purchase requests. | |
purchase ( array $parameters = [] ) : Omnipay\PayPal\Message\RestPurchaseRequest | Create a purchase request. | |
reactivateSubscription ( array $parameters = [] ) : Omnipay\PayPal\Message\RestReactivateSubscriptionRequest | Reactivate a suspended subscription. | |
refund ( array $parameters = [] ) : Omnipay\PayPal\Message\RestRefundRequest | Refund a Sale Transaction | |
refundCapture ( array $parameters = [] ) : |
Refund a Captured Payment | |
searchTransaction ( array $parameters = [] ) : Omnipay\PayPal\Message\RestCompleteSubscriptionRequest | Search for transactions. | |
setClientId ( string $value ) : |
Set OAuth 2.0 client ID for the access token. | |
setSecret ( string $value ) : |
Set OAuth 2.0 secret for the access token. | |
setToken ( string $value ) : |
Set OAuth 2.0 access token. | |
setTokenExpires ( integer $value ) : |
Set OAuth 2.0 access token expiry time. | |
suspendSubscription ( array $parameters = [] ) : Omnipay\PayPal\Message\RestSuspendSubscriptionRequest | Suspend a subscription. | |
updatePlan ( array $parameters = [] ) : Omnipay\PayPal\Message\RestUpdatePlanRequest | Update a billing plan. | |
void ( array $parameters = [] ) : |
Void an authorization. |
public cancelSubscription ( array $parameters = [] ) : Omnipay\PayPal\Message\RestCancelSubscriptionRequest | ||
$parameters | array | |
Результат | Omnipay\PayPal\Message\RestCancelSubscriptionRequest |
public completePurchase ( array $parameters = [] ) : |
||
$parameters | array | |
Результат |
public completeSubscription ( array $parameters = [] ) : Omnipay\PayPal\Message\RestCompleteSubscriptionRequest | ||
$parameters | array | |
Результат | Omnipay\PayPal\Message\RestCompleteSubscriptionRequest |
public createCard ( array $parameters = [] ) : Omnipay\PayPal\Message\RestCreateCardRequest | ||
$parameters | array | |
Результат | Omnipay\PayPal\Message\RestCreateCardRequest |
public createPlan ( array $parameters = [] ) : Omnipay\PayPal\Message\RestCreatePlanRequest | ||
$parameters | array | |
Результат | Omnipay\PayPal\Message\RestCreatePlanRequest |
public createRequest ( string $class, array $parameters = [] ) : |
||
$class | string | |
$parameters | array | |
Результат |
public createSubscription ( array $parameters = [] ) : Omnipay\PayPal\Message\RestCreateSubscriptionRequest | ||
$parameters | array | |
Результат | Omnipay\PayPal\Message\RestCreateSubscriptionRequest |
public createToken ( ) : |
||
Результат |
public deleteCard ( array $parameters = [] ) : Omnipay\PayPal\Message\RestDeleteCardRequest | ||
$parameters | array | |
Результат | Omnipay\PayPal\Message\RestDeleteCardRequest |
public fetchPurchase ( array $parameters = [] ) : Omnipay\PayPal\Message\RestFetchPurchaseRequest | ||
$parameters | array | |
Результат | Omnipay\PayPal\Message\RestFetchPurchaseRequest |
public fetchTransaction ( array $parameters = [] ) : Omnipay\PayPal\Message\RestFetchTransactionRequest | ||
$parameters | array | |
Результат | Omnipay\PayPal\Message\RestFetchTransactionRequest |
public getClientId ( ) : string | ||
Результат | string |
public getTokenExpires ( ) : integer | ||
Результат | integer |
public listPurchase ( array $parameters = [] ) : Omnipay\PayPal\Message\RestListPurchaseRequest | ||
$parameters | array | |
Результат | Omnipay\PayPal\Message\RestListPurchaseRequest |
public reactivateSubscription ( array $parameters = [] ) : Omnipay\PayPal\Message\RestReactivateSubscriptionRequest | ||
$parameters | array | |
Результат | Omnipay\PayPal\Message\RestReactivateSubscriptionRequest |
public refundCapture ( array $parameters = [] ) : |
||
$parameters | array | |
Результат |
public searchTransaction ( array $parameters = [] ) : Omnipay\PayPal\Message\RestCompleteSubscriptionRequest | ||
$parameters | array | |
Результат | Omnipay\PayPal\Message\RestCompleteSubscriptionRequest |
public setClientId ( string $value ) : |
||
$value | string | |
Результат | provides a fluent interface |
public setTokenExpires ( integer $value ) : |
||
$value | integer | |
Результат | provides a fluent interface |
public suspendSubscription ( array $parameters = [] ) : Omnipay\PayPal\Message\RestSuspendSubscriptionRequest | ||
$parameters | array | |
Результат | Omnipay\PayPal\Message\RestSuspendSubscriptionRequest |
public updatePlan ( array $parameters = [] ) : Omnipay\PayPal\Message\RestUpdatePlanRequest | ||
$parameters | array | |
Результат | Omnipay\PayPal\Message\RestUpdatePlanRequest |