|
|
@@ -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.'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |