Skip to content
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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"aimeos/aimeos-core": "dev-master",
"omnipay/common": "~3.0",
"php-http/httplug": "~2.0",
"php-http/curl-client": "~2.0"
"php-http/curl-client": "~2.0",
"stripe/stripe-php": "^7.80"
},
"require-dev": {
"phpunit/phpunit": "~7.0||~8.0||~9.0",
Expand Down
88 changes: 88 additions & 0 deletions lib/custom/src/MShop/Service/Provider/Payment/StripeApi.php
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', [] );
Comment on lines +50 to +59
Copy link
Collaborator

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.

Copy link
Author

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

}


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 );
}
}