-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stripe plugin for Api #34
Open
kappa-london
wants to merge
1
commit into
aimeoscom:master
Choose a base branch
from
kappa-london:Stripe
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
88 changes: 88 additions & 0 deletions
88
lib/custom/src/MShop/Service/Provider/Payment/StripeApi.php
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,88 @@ | ||
<?php | ||
|
||
namespace Aimeos\MShop\Service\Provider\Payment; | ||
// This is to use for Stripe Api and SCA method | ||
class StripeApi | ||
extends \Aimeos\MShop\Service\Provider\Payment\Base | ||
implements \Aimeos\MShop\Service\Provider\Payment\Iface | ||
{ | ||
public function isImplemented( $what ):bool | ||
{ | ||
switch( $what ) | ||
{ | ||
case \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_CAPTURE: | ||
case \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_REFUND: | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Tries to get an authorization or captures the money immediately for the given | ||
* order if capturing isn't supported or not configured by the shop owner. | ||
* | ||
* @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object | ||
* @parame array $params Request parameter if available | ||
* @return \Illuminate\Http\JsonResponse Form object with URL, action | ||
* and parameters to redirect to (e.g. to an external server of the payment | ||
* provider or to a local success page) | ||
*/ | ||
public function process( \Aimeos\MShop\Order\Item\Iface $order, array $params = [] ):\Aimeos\MShop\Common\Helper\Form\Iface | ||
{ | ||
$basket = $this->getOrderBase( $order->getBaseId() ); | ||
$total = ($basket->getPrice()->getValue() + $basket->getPrice()->getCosts()) *100; | ||
$currency = $basket->getLocale()->getCurrencyId(); | ||
|
||
// send the payment details to an external payment gateway | ||
|
||
|
||
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET')); | ||
$intent = \Stripe\PaymentIntent::create([ | ||
'amount' => $total, | ||
'currency' => $currency, | ||
'metadata' => ['integration_check' => 'accept_a_payment'], | ||
]); | ||
|
||
$status = \Aimeos\MShop\Order\Item\Base::PAY_PENDING; | ||
$order->setPaymentStatus( $status ); | ||
$this->saveOrder( $order ); | ||
|
||
header('Access-Control-Allow-Origin: http://127.0.0.1:3000'); | ||
header('Access-Control-Allow-Credentials: true'); | ||
print json_encode(['data'=>['clientSecret'=>$intent->client_secret],'info'=>[ | ||
'amount' => $total, | ||
'currency' => $currency, | ||
'metadata' => ['integration_check' => 'accept_a_payment'], | ||
'verify'=>$this->getConfigValue( 'payment.url-update' ) | ||
]]); | ||
exit; | ||
// return new \Aimeos\MShop\Common\Helper\Config\Standard( '', 'POST', [] ); | ||
} | ||
|
||
|
||
public function updateSync( \Psr\Http\Message\ServerRequestInterface $request, \Aimeos\MShop\Order\Item\Iface $order ):\Aimeos\MShop\Order\Item\Iface | ||
{ | ||
// extract status from the request | ||
// map the status value to one of the Aimeos payment status values | ||
|
||
|
||
|
||
$status = \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED; | ||
$order->setPaymentStatus( $status ); | ||
$this->saveOrder( $order ); | ||
|
||
return $order; | ||
} | ||
|
||
|
||
public function refund( \Aimeos\MShop\Order\Item\Iface $order ):\Aimeos\MShop\Order\Item\Iface | ||
{ | ||
$orderid = $order->getId(); | ||
// ask the payment gateway to refund the complete payment for the given order | ||
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET')); | ||
|
||
$status = \Aimeos\MShop\Order\Item\Base::PAY_REFUND; | ||
$order->setPaymentStatus( $status ); | ||
$this->saveOrder( $order ); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You definitely need to use the Form helper to return the data to the client in a jsonapi.org compatible format. This means that you need to change your PWA client that it doesn't expect this format but JSON API standard format instead. Your custom data will then be available in the "meta" section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will come back with another implementation. Many thanks for answering