John Davidson

php - PayPal Payment Definition: Trial & Regular

0 comments
Message:


As some may have noticed PayPal's SDK documentation can be quite poor to say the least, creating issues for developers.


My current is is regarding the Billing Plan payment_definitions.


I have developed a discount feature which will in return give a discount for a specified amount to the user. I wish for this discount to be applied only for first month. The poor documentation regarding the billing plan is confusing me when it comes to creating the payment definition object. Is it possible to have both a trial and a regular payment definition defined?


See below code for my example of what I am working with at the moment.


        if(Wo_DiscountAvailable($discount)){
// (total-(total/100*percentage))
$dc_total = ($total-(Wo_DiscountPercentage($discount)/100*$total));
$tDefinition = new \PayPal\Api\PaymentDefinition();
$tDefinition->setName('Regular Payments user' . $wo['user']['id'])->setType('TRIAL')
->setFrequency($p_type)->setFrequencyInterval('1')
->setCycles('1')
->setAmount(new \PayPal\Api\Currency(array(
'value' => $dc_total,
'currency' => $wo['config']['paypal_currency']
)));
$paymentDefinition = new \PayPal\Api\PaymentDefinition();
$paymentDefinition->setName('Regular Payments user' . $wo['user']['id'])->setType('REGULAR')
->setFrequency($p_type)->setFrequencyInterval('1')
->setCycles('47')
->setAmount(new \PayPal\Api\Currency(array(
'value' => $total,
'currency' => $wo['config']['paypal_currency']
)));
} else {
// Set billing plan definitions
$paymentDefinition = new \PayPal\Api\PaymentDefinition();
$paymentDefinition->setName('Regular Payments user' . $wo['user']['id'])->setType('REGULAR')
->setFrequency($p_type)->setFrequencyInterval('1')
->setCycles('48')
->setAmount(new \PayPal\Api\Currency(array(
'value' => $total,
'currency' => $wo['config']['paypal_currency']
)));
}

if(Wo_DiscountAvailable($discount)){
$plan->setPaymentDefinitions(array(
$tDefinition, $paymentDefinition
));
} else {
$plan->setPaymentDefinitions(array(
$paymentDefinition
));
}

Above include functions Wo_DiscountAvailable and Wo_DiscountPercentage - these both work


The former function returns true or false if it is available for use and discount returns value of discount.


Many thanks in advance.



My Answer:
In the code snippet provided, you are creating two payment definitions - one for the trial period and one for the regular period. This approach is correct for setting up a trial period followed by regular payments.

The trial payment definition is set up with a type of 'TRIAL' and a cycle of 1, indicating that it will only be applied for the first payment. The regular payment definition is set up with a type of 'REGULAR' and a cycle of 47 or 48, depending on whether a discount is available.

If a discount is available, the discount amount is applied to the total for the trial period, and the regular payment definition is set up with the original total amount. If no discount is available, the regular payment definition is set up with the original total amount.

Overall, the code looks correct for setting up a trial and regular payment definition with the possibility of applying a discount for the trial period. If you are experiencing issues with the PayPal SDK documentation, you may need to experiment with different configurations or reach out to PayPal support for further assistance.

Rate this post

4 of 5 based on 8151 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us