-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e455460
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# PayPal REST Payment Module | ||
|
||
The Payum extension to purchase through PayPal using REST API | ||
|
||
## Install and Use | ||
|
||
To install, it's easiest to use composer: | ||
|
||
composer require cognito/payum_paypal_rest | ||
|
||
### Build the config | ||
|
||
```php | ||
<?php | ||
|
||
use Payum\Core\PayumBuilder; | ||
use Payum\Core\GatewayFactoryInterface; | ||
|
||
$defaultConfig = []; | ||
|
||
$payum = (new PayumBuilder) | ||
->addGatewayFactory('paypal_rest', function(array $config, GatewayFactoryInterface $coreGatewayFactory) { | ||
return new \Cognito\PayumPayPalRest\PayPalRestGatewayFactory($config, $coreGatewayFactory); | ||
}) | ||
|
||
->addGateway('paypal_rest', [ | ||
'factory' => 'paypal_rest', | ||
'publishable_key' => 'Your Public Key', | ||
'secret_key' => 'Your Private Key', | ||
'img_url' => 'https://path/to/logo/image.jpg', | ||
'img_2_url' => 'https://path/to/logo/pay_by_image.jpg', | ||
]) | ||
|
||
->getPayum() | ||
; | ||
``` | ||
|
||
### Request payment | ||
|
||
```php | ||
<?php | ||
|
||
use Payum\Core\Request\Capture; | ||
|
||
$storage = $payum->getStorage(\Payum\Core\Model\Payment::class); | ||
$request = [ | ||
'invoice_id' => 100, | ||
]; | ||
|
||
$payment = $storage->create(); | ||
$payment->setNumber(uniqid()); | ||
$payment->setCurrencyCode($currency); | ||
$payment->setTotalAmount(100); // Total cents | ||
$payment->setDescription(substr($description, 0, 45)); | ||
$payment->setDetails([ | ||
]); | ||
$storage->setInternalDetails($payment, $request); | ||
|
||
$captureToken = $payum->getTokenFactory()->createCaptureToken('paypal_rest', $payment, 'done.php'); | ||
$url = $captureToken->getTargetUrl(); | ||
header("Location: " . $url); | ||
die(); | ||
``` | ||
|
||
### Check it worked | ||
|
||
```php | ||
<?php | ||
/** @var \Payum\Core\Model\Token $token */ | ||
$token = $payum->getHttpRequestVerifier()->verify($request); | ||
$gateway = $payum->getGateway($token->getGatewayName()); | ||
|
||
/** @var \Payum\Core\Storage\IdentityInterface $identity **/ | ||
$identity = $token->getDetails(); | ||
$model = $payum->getStorage($identity->getClass())->find($identity); | ||
$gateway->execute($status = new GetHumanStatus($model)); | ||
|
||
/** @var \Payum\Core\Request\GetHumanStatus $status */ | ||
|
||
// using shortcut | ||
if ($status->isNew() || $status->isCaptured() || $status->isAuthorized()) { | ||
// success | ||
} elseif ($status->isPending()) { | ||
// most likely success, but you have to wait for a push notification. | ||
} elseif ($status->isFailed() || $status->isCanceled()) { | ||
// the payment has failed or user canceled it. | ||
} | ||
``` | ||
|
||
## License | ||
|
||
Payum PayPal Rest is released under the [MIT License](LICENSE). |