Skip to content

Instantly share code, notes, and snippets.

View New0's full-sized avatar

Nico Figueira Mahe New0

View GitHub Profile
@New0
New0 / filter_direct_stripe_subscription_data.php
Last active July 12, 2018 09:43
Filter Subscription data in Direct Stripe and use trial period set in Stripe's product pricing plan
<?php
/*
* Plugin Name: Direct Stripe Trial Period
* Description: Use trial period set in a pricing plan
* Author: Nicolas Figueira New0
* Author URI: https://newo.me
* Version: 0.0.1
*/
add_filter('direct_stripe_subscription_data', function( $subscriptiondata ) {
@New0
New0 / ds-filter-params.php
Last active August 28, 2018 07:37
Set email address used for Stripe modal form using url parameter
<?php
/*
* The 'ds_filter_params' filter hook will be available from Direct Stripe 2.1.8
*/
add_filter( 'ds_filter_params', function( $params ){
$email = $_GET['email']; //url parameter set as [email protected]
if( isset($email) ){
$params['current_email_address'] = $email;
}
return $params;
@New0
New0 / ds-donation-currency.php
Created August 28, 2018 07:59
Add the currency the Direct Stripe donation button is set with.
<?php
//We add a span tag that holds the currency text corresponding to a donation button
add_filter( 'direct_stripe_donation_input', function( $direct_stripe_donation_input, $instance, $button_id ) {
if( $button_id === 'ds-dons' ){ // $button_id is the CSS ID set in the button settings
$text = 'EUR';
} else if( $button_id === 'ds-donation' ){ // $button_id is the CSS ID set in the button settings
$text= 'USD';
}
$direct_stripe_donation_input .= '<span class="curency-info">' . $text . '</span>';
@New0
New0 / ds_add_charge_metadata.php
Last active September 15, 2018 09:18
Direct Stripe Charge Add metadata to be stored ain the Stripe charge
<?php
/*
* Plugin Name: Direct Stripe Charges Description to Metadata
*/
/*
* Use 'direct_stripe_charge_data' to pass metadata values to Stripe charge
* @2.1.9
*/
add_filter('direct_stripe_charge_data', function($chargedata, $user, $token, $amount, $currency, $capture, $description, $button_id) {
@New0
New0 / ds-custom-code-how-to.md
Last active September 23, 2018 17:05
Add a description to the Charge event triggered by a Direct Stripe Subscription

How to add a description to a charge triggered by a subscription of Direct Stripe WordPress plugin plugin

First steps from your Stripe dashboard

  • Log in the Stripe Dashboard

  • Add a webhook endpoint in Developers -> Webhooks -> ( Add endpoint ) button

@New0
New0 / ds-edit-tc-link.php
Created October 1, 2018 08:58
Edit the T&C text and link of a Direct Stripe button
@New0
New0 / ds-filter-params-amount.php
Last active October 5, 2018 07:38
Set the amount of a Direct Stripe button based on a variable available on page load
<?php
/*
* The 'ds_filter_params' filter hook is available since Direct Stripe 2.1.8
*
* We want to set the amount based on a query parameter sent on the previous page, (or any variable available on page load)
* We called the query variable ds_amount
*/
add_filter( 'ds_filter_params', function( $params ){
if( $params['button_id'] === 'MyButtonID' ) { //EDIT 'MyButtonID' with your own CSS Button ID
@New0
New0 / ds-activate-trial.php
Last active October 19, 2018 06:54
Activate Trial_from_plan = true in Direct Stripe subscription button
<?php
/*
* Plugin Name: DS Activate Trial
* Author: Nicolas Figueira
* Description: Add Activate Trial acttribute for a Direct Stripe Subscription button
* Plugin URI: https://gist.github.com/New0/9044c5e50732883342f844c5b7fb7b85
*
* This code is an add-on of Direct Stripe WordPress plugin
*/
add_action( 'direct_stripe_subscription_data', function($subscriptiondata, $user, $token, $button_id, $plan_id, $coupon, $description) {
@New0
New0 / ds-custom-code.php
Created November 29, 2018 17:41
Custom WordPress plugin used as an extension of Direct Stripe Plugin
<?php
/*
* Plugin Name: DS custom code
* Author: Nicolas Figueira
* Description: Direct Stripe custom actions and filters
* Plugin URI: https://gist.github.com/New0/d72217de1e60871cf938715c2fd03b61
*
* This code is an add-on of Direct Stripe WordPress plugin
*/
@New0
New0 / mockUtils.js
Last active December 18, 2018 15:28
mocUtils for render files field
//https://gist.github.com/josephhanson/372b44f93472f9c5a2d025d40e7bb4cc
function MockFile() {
};
MockFile.prototype.create = function (name, size, mimeType) {
name = name || "mock.txt";
size = size || 1024;
mimeType = mimeType || 'plain/txt';
function range(count) {