Stripe is a commonly used payment gateway. Stripe integration in Drupal 8 requires a stripe library. We can install the stripe library using Composer. Use the following command to install the stripe library using which Stripe integration in Drupal 8 is possible.
public function buildForm(array $form, FormStateInterface $form_state) { $stripe=array("secret_key"=> "********************", //Give your api keys for stripe account "publishable_key"=> "********************" //Give your api keys for stripe account ); \Stripe\Stripe: :setApiKey($stripe['secret_key']); $publishable_key=$stripe['publishable_key']; $stripe_email=$_SESSION['stripe_email']; //Give your mail id $amount=100; //Give your amount to be transfer $stripe amount=$amount *100; $form ['pay_button']=array('#type'=> 'markup', '#markup'=> new FormattableMarkup('
', []), ); $form['submit']=array('#type'=> 'submit', '#value'=> $this-> t('Save'), '#button_type'=> 'primary', ); return $form; } /** * {@inheritdoc} */ public function submitForm(array & $form, FormStateInterface $form_state) { $token=$_POST['stripeToken']; $stripe=array("secret_key"=> "********************", "publishable_key"=> "********************" ); \Stripe\Stripe: :setApiKey($stripe['secret_key']); $customer=\Stripe\Customer: :create(array('email'=> $mail, //give your mail id 'card'=> $token)); $description="User Registration"; $charge=\Stripe\Charge: :create(array("amount"=> $amount, //Give your amount to be transfer, 'customer'=> $customer-> id, "currency"=> "EUR", //You can change the currency format "description"=> $description)); $msg="Successfully charged ".$amount; drupal_set_message($msg); }
The easiest way to solve an issue is to let it deal with by experts. We can provide a wide range of services, which will help you maintain and manage your websites. Get in touch with us to know more.