function mcs_paypal_form($price, $currency, $discount_rate, $discounts, $discount, $quantity) { if (!get_option('mcs_paypal_merchant_id')) { $form = "<p class='warning'>" . __('PayPal account is not configured.', 'my-calendar-submissions') . "</p>"; } else { $use_sandbox = get_option('mcs_use_sandbox'); $button = get_option('mcs_button'); $form = "\n\t\t<form action='" . ($use_sandbox != 'true' ? "https://www.paypal.com/cgi-bin/webscr" : "https://www.sandbox.paypal.com/cgi-bin/webscr") . "' method='POST'>\n\t\t<input type='hidden' name='cmd' value='_xclick' />\n\t\t<input type='hidden' name='business' value='" . get_option('mcs_paypal_merchant_id') . "' />\n\t\t<input type='hidden' name='item_name' value='" . sprintf(__('%s Event Submission', 'my-calendar-submissions'), get_option('blogname')) . "' />\n\t\t<input type='hidden' name='item_number' value='1' />\n\t\t<input type='hidden' name='amount' value='{$price}' />\n\t\t<input type='hidden' name='no_shipping' value='1' />\n\t\t<input type='hidden' name='no_note' value='1' />\n\t\t<input type='hidden' name='currency_code' value='{$currency}' />"; $search = "http"; $replace = "https"; $form .= "\n\t\t<input type='hidden' name='notify_url' value='" . mcs_replace_http(add_query_arg('mcsipn', 'true', home_url())) . "' />\n\t\t<input type='hidden' name='return' value='" . mcs_replace_http(add_query_arg('response_code', 'thanks', mc_get_current_url())) . "' />\n\t\t<input type='hidden' name='cancel_return' value='" . mcs_replace_http(add_query_arg('response_code', 'cancel', mc_get_current_url())) . "' />"; if ($discount == true && $discount_rate > 0) { $form .= "\n\t\t\t<input type='hidden' name='discount_rate' value='{$discount_rate}' />"; if ($quantity == 'true') { $form .= "\n\t\t\t\t<input type='hidden' name='discount_rate2' value='{$discount_rate}' />"; } } if ($button != '' && mc_is_url($button)) { $form .= "<input type='image' src='{$button}' name='submit' class='button' alt='" . __('Buy a payment key', 'my-calendar-submissions') . "' />"; } else { $form .= "<input type='submit' name='submit' class='button' value='" . __('Buy a payment key', 'my-calendar-submissions') . "' />"; } if ($quantity == 'true') { $form .= "\n\t\t\t<p><label for='quantity'>" . __('Quantity', 'my-calendar-submissions') . "</label> <input type='number' name='quantity' value='1' id='quantity' size='3' /></p>"; } $form .= apply_filters('mcs_paypal_form', '', $price, $currency, $discount_rate, $discounts, $discount); $form .= "</form>"; } return $form; }
/** * Generate a sample form for use in a demo Direct Post implementation. * * @param string $amount Amount of the transaction. * @param string $fp_sequence Sequential number(ie. Invoice #) * @param string $relay_response_url The Relay Response URL * @param string $api_login_id Your API Login ID * @param string $transaction_key Your API Tran Key. * * @return string */ public static function getCreditCardForm($price, $fp_sequence, $relay_response_url, $api, $key, $nonce) { $test_mode = get_option('mcs_use_sandbox') == 'true' ? true : false; $prefill = $test_mode ? true : false; $time = time(); $fp = self::getFingerprint($api, $key, $price, $fp_sequence, $time); $sim = new AuthorizeNetSIM_Form(array('x_amount' => $price, 'x_fp_sequence' => $fp_sequence, 'x_fp_hash' => $fp, 'x_fp_timestamp' => $time, 'x_relay_response' => "TRUE", 'x_relay_url' => $relay_response_url, 'x_login' => $api)); $hidden_fields = $sim->getHiddenFieldString(); global $wp; $hidden_fields .= "<input type='hidden' name='x_referer_url' value='" . mcs_replace_http(home_url(add_query_arg(array(), $wp->request))) . "' />"; $post_url = $test_mode ? self::SANDBOX_URL : self::LIVE_URL; $button = get_option('mcs_button'); $quantity = isset($_POST['mcs_quantity']) ? (int) $_POST['mcs_quantity'] : 1; if ($quantity == 1) { $purchasing = '<p>' . sprintf(__('You\'re purchasing a payment key to submit %1$s event for $%2$s.', 'my-calendar-submissions'), "<strong>{$quantity}</strong>", "<strong>{$price}</strong>") . '</p>'; } else { $purchasing = ' <p>' . sprintf(__('You\'re purchasing a payment key for %1$s events. Total: $%2$s.', 'my-calendar-submissions'), "<strong>{$quantity}</strong>", "<strong>{$price}</strong>") . '</p>'; } $form = $purchasing . ' <form method="post" action="' . $post_url . '"> <div> ' . $hidden_fields . ' <input type="hidden" name="x_amount_base" value="' . $price . '" /> </div> <div> <label for="x_card_num">' . __('Credit Card Number', 'my-calendar-submissions') . '</label> <input type="text" required aria-required="true" size="17" id="x_card_num" name="x_card_num" value="' . ($prefill ? '6011000000000012' : '') . '" /> </div> <div> <label for="x_exp_date">' . __('Expiration', 'my-calendar-submissions') . '</label> <input type="text" required aria-required="true" size="4" id="x_exp_date" name="x_exp_date" placeholder="05/' . date('y', strtotime('+ 2 years')) . '" value="' . ($prefill ? '04/17' : '') . '" /> </div> <div> <label for="x_card_code">' . __('Security Code', 'my-calendar-submissions') . '</label> <input type="text" required aria-required="true" size="4" id="x_card_code" name="x_card_code" placeholder="123" value="' . ($prefill ? '782' : '') . '" /> </div> <div> <label for="x_first_name">' . __('First Name', 'my-calendar-submissions') . '</label> <input type="text" required aria-required="true" size="17" id="x_first_name" name="x_first_name" value="' . ($prefill ? 'John' : '') . '" /> </div> <div> <label for="x_last_name">' . __('Last Name', 'my-calendar-submissions') . '</label> <input type="text" required aria-required="true" size="17" id="x_last_name" name="x_last_name" value="' . ($prefill ? 'Doe' : '') . '" /> </div> <div> <label for="x_payer_email">' . __('Email', 'my-calendar-submissions') . '</label> <input type="email" required aria-required="true" size="17" id="x_payer_email" name="x_payer_email" value="' . ($prefill ? '*****@*****.**' : '') . '" /> </div> <div> <label for="x_address">' . __('Address', 'my-calendar-submissions') . '</label> <input type="text" size="26" id="x_address" name="x_address" value="' . ($prefill ? '123 Main Street' : '') . '" /> </div> <div> <label for="x_city">' . __('City', 'my-calendar-submissions') . '</label> <input type="text" size="17" id="x_city" name="x_city" value="' . ($prefill ? 'Boston' : '') . '" /> </div> <div> <label for="x_state">' . __('State', 'my-calendar-submissions') . '</label> <input type="text" size="4" id="x_state" name="x_state" value="' . ($prefill ? 'MA' : '') . '" /> </div> <div> <label for="x_zip">' . __('Zip Code', 'my-calendar-submissions') . '</label> <input type="text" size="9" id="x_zip" name="x_zip" value="' . ($prefill ? '02142' : '') . '" /> </div> <div> <label for="x_country">' . __('Country', 'my-calendar-submissions') . '</label> <input type="text" size="22" id="x_country" name="x_country" value="' . ($prefill ? 'US' : '') . '" /> </div>'; if ($button != '' && mc_is_url($button)) { $form .= "<input type='image' src='{$button}' name='submit' class='button' alt='" . __('Buy a payment key', 'my-calendar-submissions') . "' />"; } else { $form .= "<input type='submit' name='submit' class='button' value='" . __('Buy a payment key', 'my-calendar-submissions') . "' />"; } $form .= apply_filters('mcs_authorizenet_form', '', $price); $form .= '</form>'; return $form; }