-
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
1 parent
e455460
commit 2b1c189
Showing
13 changed files
with
775 additions
and
2 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,19 @@ | ||
Copyright (C) 2015 Maksim Kotlyar | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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
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,35 @@ | ||
{ | ||
"name": "cognito/payum_paypal_rest", | ||
"type": "library", | ||
"description": "The Payum PayPal REST payment module", | ||
"keywords": ["payment"], | ||
"homepage": "https://payum.forma-pro.com", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Josh Marshall", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Kotlyar Maksim", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Payum project", | ||
"homepage": "https://payum.forma-pro.com/" | ||
}, | ||
{ | ||
"name": "Community contributions", | ||
"homepage": "https://github.com/joshbmarshall/payum_paypal_rest/contributors" | ||
} | ||
], | ||
"require": { | ||
"payum/core": "^1.5" | ||
}, | ||
"config": { | ||
"bin-dir": "bin" | ||
}, | ||
"autoload": { | ||
"psr-4": { "Cognito\\PayumPayPalRest\\": "src/" } | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
namespace Payum\Skeleton\Action\Api; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\ApiAwareInterface; | ||
use Payum\Core\ApiAwareTrait; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Skeleton\Api; | ||
|
||
abstract class BaseApiAwareAction implements ActionInterface, GatewayAwareInterface, ApiAwareInterface | ||
{ | ||
use GatewayAwareTrait; | ||
use ApiAwareTrait; | ||
|
||
public function __construct() | ||
{ | ||
$this->apiClass = Api::class; | ||
} | ||
} |
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,80 @@ | ||
<?php | ||
|
||
namespace Cognito\PayumPayPalRest\Action; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\Request\Capture; | ||
use Cognito\PayumPayPalRest\Request\Api\ObtainNonce; | ||
|
||
class CaptureAction implements ActionInterface, GatewayAwareInterface { | ||
use GatewayAwareTrait; | ||
|
||
private $config; | ||
|
||
/** | ||
* @param string $templateName | ||
*/ | ||
public function __construct(ArrayObject $config) { | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param Capture $request | ||
*/ | ||
public function execute($request) { | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$model = ArrayObject::ensureArrayObject($request->getModel()); | ||
if ($model['status']) { | ||
return; | ||
} | ||
|
||
/* | ||
\Stripe\Stripe::setApiKey($this->config['secret_key']); | ||
$model['publishable_key'] = $this->config['publishable_key']; | ||
$model['img_url'] = $this->config['img_url'] ?? ''; | ||
$model['img_2_url'] = $this->config['img_2_url'] ?? ''; | ||
$obtainNonce = new ObtainNonce($request->getModel()); | ||
$obtainNonce->setModel($model); | ||
$this->gateway->execute($obtainNonce); | ||
if (!$model->offsetExists('status')) { | ||
$stripe = new \Stripe\StripeClient($this->config['secret_key']); | ||
$paymentIntent = $stripe->paymentIntents->retrieve($model['nonce'], []); | ||
if ($paymentIntent->status == \Stripe\PaymentIntent::STATUS_SUCCEEDED) { | ||
$model['status'] = 'success'; | ||
} else { | ||
// Report error | ||
$model['status'] = 'failed'; | ||
$model['error'] = 'failed'; | ||
} | ||
foreach ($paymentIntent->charges ?? [] as $charge) { | ||
$model['transactionReference'] = $charge->id; | ||
$model['result'] = $charge; | ||
} | ||
if ($paymentIntent->latest_charge ?? false) { | ||
$model['transactionReference'] = $paymentIntent->latest_charge; | ||
$charge = $stripe->charges->retrieve($paymentIntent->latest_charge); | ||
$model['stripe_charge_info'] = $charge; | ||
} | ||
} | ||
*/ | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function supports($request) { | ||
return | ||
$request instanceof Capture && | ||
$request->getModel() instanceof \ArrayAccess; | ||
} | ||
} |
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,52 @@ | ||
<?php | ||
namespace Cognito\PayumPayPalRest\Action; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\Model\PaymentInterface; | ||
use Payum\Core\Request\Convert; | ||
use Payum\Core\Request\GetCurrency; | ||
|
||
class ConvertPaymentAction implements ActionInterface, GatewayAwareInterface | ||
{ | ||
use GatewayAwareTrait; | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param Convert $request | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
/** @var PaymentInterface $payment */ | ||
$payment = $request->getSource(); | ||
|
||
$details = ArrayObject::ensureArrayObject($payment->getDetails()); | ||
$this->gateway->execute($currency = new GetCurrency($payment->getCurrencyCode())); | ||
$divisor = pow(10, $currency->exp); | ||
$details["amount"] = $payment->getTotalAmount() / $divisor; | ||
$details["currency"] = $payment->getCurrencyCode(); | ||
$details["currencySymbol"] = $currency->alpha3; | ||
$details["currencyDigits"] = $currency->exp; | ||
$details["description"] = $payment->getDescription(); | ||
|
||
$request->setResult((array) $details); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof Convert && | ||
$request->getSource() instanceof PaymentInterface && | ||
$request->getTo() == 'array' | ||
; | ||
} | ||
} |
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,81 @@ | ||
<?php | ||
|
||
namespace Cognito\PayumPayPalRest\Action; | ||
|
||
use Cognito\PayumPayPalRest\Request\Api\ObtainNonce; | ||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\Exception\LogicException; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\Reply\HttpResponse; | ||
use Payum\Core\Request\GetHttpRequest; | ||
use Payum\Core\Request\RenderTemplate; | ||
|
||
class ObtainNonceAction implements ActionInterface, GatewayAwareInterface { | ||
use GatewayAwareTrait; | ||
|
||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $templateName; | ||
|
||
/** | ||
* @param string $templateName | ||
*/ | ||
public function __construct(string $templateName) { | ||
$this->templateName = $templateName; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function execute($request) { | ||
/** @var $request ObtainNonce */ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$model = ArrayObject::ensureArrayObject($request->getModel()); | ||
|
||
if ($model['card']) { | ||
throw new LogicException('The token has already been set.'); | ||
} | ||
$uri = \League\Uri\Http::createFromServer($_SERVER); | ||
|
||
$getHttpRequest = new GetHttpRequest(); | ||
$this->gateway->execute($getHttpRequest); | ||
// Received payment intent information from Stripe | ||
if (isset($getHttpRequest->request['payment_intent'])) { | ||
$model['nonce'] = $getHttpRequest->request['payment_intent']; | ||
return; | ||
} | ||
$paymentIntentData = [ | ||
'amount' => round($model['amount'] * pow(10, $model['currencyDigits'])), | ||
'shipping' => $model['shipping'], | ||
'currency' => $model['currency'], | ||
'metadata' => ['integration_check' => 'accept_a_payment'], | ||
'statement_descriptor' => $model['statement_descriptor_suffix'], | ||
'description' => $model['description'], | ||
]; | ||
|
||
$this->gateway->execute($renderTemplate = new RenderTemplate($this->templateName, array( | ||
'amount' => $model['currencySymbol'] . ' ' . number_format($model['amount'], $model['currencyDigits']), | ||
'actionUrl' => $uri->withPath('')->withFragment('')->withQuery('')->__toString() . $getHttpRequest->uri, | ||
'imgUrl' => $model['img_url'], | ||
'img2Url' => $model['img_2_url'], | ||
'billing' => $model['billing'] ?? [], | ||
))); | ||
|
||
throw new HttpResponse($renderTemplate->getResult()); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function supports($request) { | ||
return | ||
$request instanceof ObtainNonce && | ||
$request->getModel() instanceof \ArrayAccess; | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
namespace Cognito\PayumPayPalRest\Action; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Request\GetStatusInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
|
||
class StatusAction implements ActionInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param GetStatusInterface $request | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$model = ArrayObject::ensureArrayObject($request->getModel()); | ||
|
||
if ($model['error']) { | ||
$request->markFailed(); | ||
|
||
return; | ||
} | ||
|
||
if (false == $model['status'] && false == $model['nonce']) { | ||
$request->markNew(); | ||
|
||
return; | ||
} | ||
if ('success' == $model['status']) { | ||
$request->markCaptured(); | ||
|
||
return; | ||
} | ||
$request->markUnknown(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof GetStatusInterface && | ||
$request->getModel() instanceof \ArrayAccess | ||
; | ||
} | ||
} |
Oops, something went wrong.