Reputation: 1541
I'm trying to create a web service using PHP to set up a Stripe integration, using an already-existing Wordpress-based site. I've read Stripe's official website on how to do this, and I more or less understand what's going on, but I'm faced with a very very fundamental problem:
If you haven’t already, install the library for your favorite language now.
How in blazes do you install the library?
I've been to Stripe's client library site, which has a PHP client library for download and also for Composer installation. I've searched for how to add Composer to PHP, but it doesn't seem very easy. I've also downloaded the library, but I'm not very sure how to install it into the Wordpress directory.
I haven't done web programming for quite some time so please bear with me. Perhaps someone could point me in the direction of installing a third-party library into a Wordpress-based website, and referencing it from .php pages after?
Upvotes: 3
Views: 4323
Reputation: 681
Simply, you can create a plugin directory in the plugins folder and upload to it the php stripe library.
Finally, require the library before using it:
require_once WP_PLUGIN_DIR . '/my-stripe-plugin/stripe-php/init.php';
Usage documentation: https://github.com/stripe/stripe-php
Upvotes: 0
Reputation: 184
You can setup a new empty plugin in WordPress, download the Stripe library and decompress in it, then you can require the init script.
require_once 'stripe/init.php'
Now you are ready to use the Stripe library.
Edit based on comments
For create a new WordPress plugin proceed as follows:
Create a new directory in wp-content/plugins
for example, myplugin
.
Decompress the Stripe folder you downloaded inside it and rename it stripe
Create a new php file called myplugin.php
Now you have this structure:
wp-content
|
-> plugins
|
-> myplugin
|
-> stripe
-> myplugin.php
Inside the php file you can put this minimal code:
<?php
/**
* Plugin Name: My Plugin
* Description: My Plugin description.
* Author: Your name
* Version: 1.0
**/
require_once 'stripe/init.php';
use Stripe\Stripe;
add_action('init', function() {
Stripe::setApiKey('my-api-key');
Stripe::setClientId('my-client-id');
});
?>
Refer to the WordPress codex for further development: https://codex.wordpress.org/Writing_a_Plugin https://codex.wordpress.org/Plugin_API
Upvotes: 6
Reputation: 1541
I've fixed this by adding a "stripes" directory to the directory I was working in, then unzipped the entire downloaded packagine into it. I simply then called it via require_once 'stripe/init.php
.
Upvotes: 0