Exemple #1
0
$paypal->API_PASSWORD = $p['password'];
$paypal->API_SIGNATURE = $p['signature'];
$paypal->profile_id = $ppid;
$paypal->version = '57.0';
//$modx->log(MODX_LEVEL_ERROR,$paypal->generateNVPString('GetRecurringPaymentsProfileDetails'));
$paypal->get_recurring_payments_profile_details();
//return $modx->error->failure(print_r($paypal->Response,true));
if (strtolower($paypal->Response['STATUS']) != 'active' || strtolower($paypal->Response['STATUS']) != 'active') {
    return $modx->error->failure($modx->lexicon('sm.error.cancelsubscription.notactive', array('status' => $paypal->Response['STATUS'])));
}
$paypal->profile_id = $ppid;
$paypal->version = '57.0';
$paypal->action = 'Cancel';
$paypal->note = $modx->lexicon('sm.notification.admincancelledsubscription');
//$modx->log(MODX_LEVEL_ERROR,$paypal->generateNVPString('ManageRecurringPaymentsProfileStatus'));
$paypal->manage_recurring_payments_profile_status();
//return $modx->error->failure(print_r($paypal->Response,true));
if (strtolower($paypal->Response['ACK']) == 'success') {
    $sub->set('active', false);
    if (!$sub->save()) {
        return $modx->error->failure($modx->lexicon('sm.error.sendmailfailed'));
    }
    // Send a notification email to notify them of the skipped payment
    /* @var modUser $user */
    $user = $modx->getObject('modUser', $sub->get('user_id'));
    $product = $sub->getOne('Product');
    if ($user instanceof modUser) {
        $result = $modx->sm->sendNotificationEmail('recurring_payment_cancelledbyadmin', $sub, $user, $product);
        if ($result !== true) {
            $modx->log(MODX_LEVEL_ERROR, 'Error sending notification email to user #' . $user->get('id') . ' for IPN type ' . $ipn_post_data['txn_type'] . ': ' . $result);
        }