/** * Process an update card form request * * @access private * @since 2.6 */ function rcp_paypal_update_billing_card($member_id = 0, $member_obj) { global $rcp_options; if (empty($member_id)) { return; } if (!is_a($member_obj, 'RCP_Member')) { return; } if (!rcp_is_paypal_subscriber($member_id)) { return; } if (rcp_is_sandbox()) { $api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp'; } else { $api_endpoint = 'https://api-3t.paypal.com/nvp'; } $error = ''; $customer_id = $member_obj->get_payment_profile_id(); $credentials = rcp_get_paypal_api_credentials(); $card_number = isset($_POST['rcp_card_number']) && is_numeric($_POST['rcp_card_number']) ? $_POST['rcp_card_number'] : ''; $card_exp_month = isset($_POST['rcp_card_exp_month']) && is_numeric($_POST['rcp_card_exp_month']) ? $_POST['rcp_card_exp_month'] : ''; $card_exp_year = isset($_POST['rcp_card_exp_year']) && is_numeric($_POST['rcp_card_exp_year']) ? $_POST['rcp_card_exp_year'] : ''; $card_cvc = isset($_POST['rcp_card_cvc']) && is_numeric($_POST['rcp_card_cvc']) ? $_POST['rcp_card_cvc'] : ''; $card_zip = isset($_POST['rcp_card_zip']) ? sanitize_text_field($_POST['rcp_card_zip']) : ''; if (empty($card_number) || empty($card_exp_month) || empty($card_exp_year) || empty($card_cvc) || empty($card_zip)) { $error = __('Please enter all required fields.', 'rcp'); } if (empty($error)) { $args = array('USER' => $credentials['username'], 'PWD' => $credentials['password'], 'SIGNATURE' => $credentials['signature'], 'VERSION' => '124', 'METHOD' => 'UpdateRecurringPaymentsProfile', 'PROFILEID' => $customer_id, 'ACCT' => $card_number, 'EXPDATE' => $card_exp_month . $card_exp_year, 'CVV2' => $card_cvc, 'ZIP' => $card_zip, 'BUTTONSOURCE' => 'EasyDigitalDownloads_SP'); $request = wp_remote_post($api_endpoint, array('timeout' => 45, 'sslverify' => false, 'body' => $args, 'httpversion' => '1.1')); $body = wp_remote_retrieve_body($request); $code = wp_remote_retrieve_response_code($request); $message = wp_remote_retrieve_response_message($request); if (is_wp_error($request)) { $error = $request->get_error_message(); } elseif (200 == $code && 'OK' == $message) { if (is_string($body)) { $body = wp_parse_str($body, $body); } if ('failure' === strtolower($body['ACK'])) { $error = $body['L_ERRORCODE0'] . ': ' . $body['L_LONGMESSAGE0']; } else { // Request was successful, but verify the profile ID that came back matches if ($customer_id !== $body['PROFILEID']) { $error = __('Error updating subscription', 'rcp'); } } } else { $error = __('Something has gone wrong, please try again', 'rcp'); } } if (!empty($error)) { wp_redirect(add_query_arg(array('card' => 'not-updated', 'msg' => urlencode($error)))); exit; } wp_redirect(add_query_arg(array('card' => 'updated', 'msg' => ''))); exit; }
/** * Determines if a member can cancel their subscription on site * * @access public * @since 2.1 */ function rcp_can_member_cancel( $user_id = 0 ) { if( empty( $user_id ) ) { $user_id = get_current_user_id(); } $ret = false; $member = new RCP_Member( $user_id ); if( $member->is_recurring() && $member->is_active() && 'cancelled' !== $member->get_status() ) { $profile_id = $member->get_payment_profile_id(); // Check if the member is a Stripe customer if( false !== strpos( $profile_id, 'cus_' ) ) { $ret = true; } elseif ( rcp_is_paypal_subscriber( $user_id ) && rcp_has_paypal_api_access() ) { $ret = true; } } return apply_filters( 'rcp_member_can_cancel', $ret, $user_id ); }
/** * Determines if a member can update the credit / debit card attached to their account * * @access public * @since 2.1 */ function rcp_member_can_update_billing_card($user_id = 0) { if (empty($user_id)) { $user_id = get_current_user_id(); } $ret = false; // Check if the member is a Stripe customer if (rcp_is_stripe_subscriber($user_id)) { $ret = true; } elseif (rcp_is_paypal_subscriber($user_id) && rcp_has_paypal_api_access()) { $ret = true; } return apply_filters('rcp_member_can_update_billing_card', $ret, $user_id); }
</td> <td><?php echo rcp_get_subscription(); ?> </td> <td><?php echo rcp_get_expiration_date(); ?> </td> <td> <?php if ((rcp_is_expired($user_ID) || !rcp_is_recurring($user_ID) || rcp_get_status($user_ID) == 'cancelled') && rcp_subscription_upgrade_possible($user_ID)) { echo '<a href="' . esc_url(get_permalink($rcp_options['registration_page'])) . '" title="' . __('Renew your subscription', 'rcp') . '" class="rcp_sub_details_renew">' . __('Renew your subscription', 'rcp') . '</a>'; } elseif (!rcp_is_active($user_ID) && rcp_subscription_upgrade_possible($user_ID)) { echo '<a href="' . esc_url(get_permalink($rcp_options['registration_page'])) . '" title="' . __('Upgrade your subscription', 'rcp') . '" class="rcp_sub_details_renew">' . __('Upgrade your subscription', 'rcp') . '</a>'; } elseif (rcp_is_active($user_ID) && rcp_is_paypal_subscriber()) { echo '<a href="https://www.paypal.com/cgi-bin/customerprofileweb?cmd=_manage-paylist" target="_blank" title="' . __('Cancel your subscription', 'rcp') . '">' . __('Cancel your subscription', 'rcp') . '</a>'; } do_action('rcp_subscription_details_action_links'); ?> </td> </tr> </tbody> </table> <table class="rcp-table" id="rcp-payment-history"> <thead> <tr> <th><?php _e('Invoice #', 'rcp'); ?> </th>
/** * Determines if a member can cancel their subscription on site * * @access public * @since 2.1 */ function rcp_can_member_cancel($user_id = 0) { if (empty($user_id)) { $user_id = get_current_user_id(); } $ret = false; $member = new RCP_Member($user_id); if ($member->is_recurring() && $member->is_active() && 'cancelled' !== $member->get_status()) { $profile_id = $member->get_payment_profile_id(); // Check if the member is a Stripe customer if (rcp_is_stripe_subscriber($user_id)) { $ret = true; } elseif (rcp_is_paypal_subscriber($user_id) && rcp_has_paypal_api_access()) { $ret = true; } elseif (rcp_is_2checkout_subscriber($user_id) && defined('TWOCHECKOUT_ADMIN_USER') && defined('TWOCHECKOUT_ADMIN_PASSWORD')) { $ret = true; } } return apply_filters('rcp_member_can_cancel', $ret, $user_id); }