Make calendar monthly subscription / fixed eot and proportional payment for the current month

I have read some threads about this but I’ve not been able to find what I’m looking for.

This is what I want.

I offer a monthly subscription for 100 usd. and I’d like to let people subscribe whenever they want. If they subscribe in the day 15, they have to pay half month and the next month will pay the full one.

This way, all the subscribers will pay the 1st day of the month.

I guess this can be done using PHP, recalculating trial time and cost in the exact time the subscription is done, but I can’t figure it out the excact code I have to implement.

The pseudo code should be:

Trial days = days to 1st day of next month.
Trial price = monthly cost * Trial days / total days of this month

Use this values to create the subscription code

I guess someone have done this before, but I havn’t not been able to find it.

I’ll thank your help.

Reagards,
Carlos.

Resolved. STILL IN TESTING MODE (I can’t explain or support this code, I just share it hoping will be useful for someone, I’m not a programmer. I have just used some example codes to create this)

I have created my own shortcodes

I have 3 shortcodes.

1st to show an information text
2nd to create a stripe form
3th to create a paypal form

[cmbsuscribinf importe=79] shows a information text
[cmbsuscribst importe=79] creates an stripe form
[cmbsuscribpp importe=79] creates an paypal form

79 is the monthly fee.

This is the CODE en my plugins PHP

//
// Suscribir por lo que queda de mes INFORMAR
//
// Hay que usar tres shortcodes juntos: Informar, Stripe y Paypal.
//

function cmb_suscribinf ( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
‘importe’ => ‘’,
‘param2’ => ‘’,
),
$atts,
‘cmbsuscribinf’
);
$string = ‘’;

$now = new DateTime('now'); 

$findemes = new DateTime('now');
$findemes->modify('last day of this month');
$diasdelmes = date("t");

//ta = precio hasta fin de mes
//tp = días hasta fin de mes

$tp = $now->diff($findemes)->format("%a");
$ta = $atts['importe'] / $diasdelmes * $tp;     

$string .= "\r\n La inscripción en la escuela es mensual. Este mes sólo abonarás la parte proporcional desde hoy hasta final de mes.";
$string .= "\r\n\r\n Cuando introduzcas los datos, se hará un cargo de ". $ta . " euros para abonar el mes en curso. ";
$string .= "\r\n\r\n El primer día del mes próximo se hará un cargo automático de la cuota completa de ".$atts['importe'].' euros';

return do_shortcode($string);
}
add_shortcode( ‘cmbsuscribinf’, ‘cmb_suscribinf’ );

//
// Fin de suscribir por lo que queda de mes INFORMAR
//

//
// Suscribir por lo que queda de mes STRIPE
//
function cmb_suscribst ( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
‘importe’ => ‘’,
‘param2’ => ‘’,
),
$atts,
‘cmbsuscribst’
);
$string = ‘’;

$now = new DateTime('now'); 

$findemes = new DateTime('now');
$findemes->modify('last day of this month');
$diasdelmes = date("t");

//ta = precio hasta fin de mes
//tp = días hasta fin de mes

$tp = $now->diff($findemes)->format("%a");
$ta = $atts['importe'] / $diasdelmes * $tp;   


$string .= '[s2Member-Pro-Stripe-Form level="4" ccaps="ecr" desc="*** Use your own text *** " cc="EUR" custom="*** Use your own text *** " ta="'.$ta.'" ';
$string .= 'tp="'.$tp.'" tt="D" ';
$string .= 'ra="'.$atts['importe'].'" ';
$string .= 'rp="1" rt="M" rr="1" coupon="" accept_coupons="1" default_country_code="US" captcha="0" /]';

return do_shortcode($string);
}
add_shortcode( ‘cmbsuscribst’, ‘cmb_suscribst’ );

//
// Fin de suscribir por lo que queda de mes STRIPE
//

//
// Suscribir por lo que queda de mes PAYPAL
//
function cmb_suscribpp ( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
‘importe’ => ‘’,
‘param2’ => ‘’,
),
$atts,
‘cmbsuscribpp’
);
$string = ‘’;

$now = new DateTime('now'); 

$findemes = new DateTime('now');
$findemes->modify('last day of this month');
$diasdelmes = date("t");

//ta = precio hasta fin de mes
//tp = días hasta fin de mes

$tp = $now->diff($findemes)->format("%a");
$ta = $atts['importe'] / $diasdelmes * $tp;   

$string .= '[s2Member-Pro-PayPal-Form level="4" ccaps="ecr" desc="*** Use your own text *** " ps="paypal" lc="" cc="EUR" dg="0" ns="1" custom="*** Use your own text *** " ta="'.$ta.'" ';
$string .= 'tp="'.$tp.'" tt="D" ';
$string .= 'ra="'.$atts['importe'].'" ';
$string .= 'rp="1" rt="M" rr="1" rrt="" rra="2" accept="paypal" accept_via_paypal="paypal" coupon="" accept_coupons="1" default_country_code="" captcha="0" /]';

return do_shortcode($string);
}
add_shortcode( ‘cmbsuscribpp’, ‘cmb_suscribpp’ );

//
// Fin de suscribir por lo que queda de mes
//

WARNING: I don’t know why, Stripe is creating the subscription as 30 days instead of 1 month.