Guillaume před 3 roky
rodič
revize
f07d27542a
3 změnil soubory, kde provedl 20 přidání a 42 odebrání
  1. +0
    -1
      backend/controllers/StripeController.php
  2. +12
    -39
      producer/controllers/CreditController.php
  3. +8
    -2
      producer/views/credit/history.php

+ 0
- 1
backend/controllers/StripeController.php Zobrazit soubor

@@ -72,7 +72,6 @@ class StripeController extends BackendController
return parent::beforeAction($action);
}


public function actionVerification()
{
// This is your Stripe CLI webhook secret for testing your endpoint locally.

+ 12
- 39
producer/controllers/CreditController.php Zobrazit soubor

@@ -93,50 +93,23 @@ class CreditController extends ProducerBaseController
'creditUser' => $userProducer->credit
]) ;
}
public function actionAdd()
public function actionStripeCharge()
{
$producer = $this->getProducer() ;
if($producer->online_payment) {
\Payplug\Payplug::setSecretKey($producer->getSecretKeyPayplug());
$creditForm = new CreditForm ;
$amount = (float) $_POST['amount'];
$source = $_POST['token_id'];

if ($creditForm->load(Yii::$app->request->post()) && $creditForm->validate()) {
$user = User::getCurrent() ;
$stripe = new \Stripe\StripeClient(
'sk_test_51IOR6uECzPeOSTMZmuDYYFdX7SyzCYHdEuyi1YAKBOFgrRNDOhoe6kaliKFmeI0XOWlTRxnwx0aw7PbuNlonGjeA00dlyCRss7'
);

$payment = \Payplug\Payment::create(array(
'amount' => (float) $creditForm->amount * 100,
'currency' => 'EUR',
'save_card' => false,
'customer' => array(
'email' => $user->email,
'first_name' => $user->name,
'last_name' => $user->lastname
),
'hosted_payment' => array(
'return_url' => Yii::$app->urlManagerProducer->createAbsoluteUrl(['credit/history', 'slug_producer' => $producer->slug, 'returnPayment' => 'success']),
'cancel_url' => Yii::$app->urlManagerProducer->createAbsoluteUrl(['credit/history', 'slug_producer' => $producer->slug, 'returnPayment' => 'cancel']),
),
'notification_url' => Yii::$app->urlManagerProducer->createAbsoluteUrl(['credit/payment-notifications', 'idUser' => $user->id, 'slug_producer' => $producer->slug]),
'metadata' => array(
'id_user' => $user->id
)
));
$stripe->charges->create([
'amount' => $amount * 100,
'currency' => 'eur',
'source' => $source,
]);

if($payment) {
$this->redirect($payment->hosted_payment->payment_url) ;
}
}

return $this->render('add', [
'creditForm' => $creditForm
]) ;
}
else {
throw new \yii\base\UserException('Cette option est désactivée chez ce producteur.');
}
}
}

+ 8
- 2
producer/views/credit/history.php Zobrazit soubor

@@ -59,7 +59,8 @@ if ($this->context->getProducer()->online_payment) {
<div id="button-test-payment-stripe">
<?=
StripeCheckoutCustom::widget([
'action' => '/',
//'action' => '/',
'action' => Yii::$app->urlManagerProducer->createUrl(['credit/stripe-charge']),
'label' => 'Alimenter 20 €',
'panelLabel' => 'Payer',
'currency' => 'EUR',
@@ -73,7 +74,12 @@ if ($this->context->getProducer()->online_payment) {
'tokenFunction' => new JsExpression(
'function(token) {
console.log(token);
//window.location.href = opendistrib_base_url(true)+"credit/history?returnPayment=success" ;
$.post(opendistrib_base_url(true)+"credit/stripe-charge", {
amount: 20,
token_id: token.id
}, function(data) {
window.location.href = opendistrib_base_url(true)+"credit/history?returnPayment=success" ;
});
}'
),
]);

Načítá se…
Zrušit
Uložit