Credit card fields are special fields in iframes. Neither the FundraisingBox nor your server has direct access to the safety critical number and secure id. So these fields need a special treatment of handling and we recommend to use our jQuery-Plugin which does a lot of helpful automatic work for you.
Required fields
The plugin automatically loads the extra javascript if all required credit card fields with following IDs exist.
- payment_credit_card_owner
- payment_credit_card_token
- payment_credit_card_number (div for iframe)
- payment_credit_card_number_hidden
- payment_credit_card_secure_id (div for iframe)
- payment_credit_card_secure_id_hidden
Additional if micropayment is used:
- payment_credit_card_expire_date_month
- payment_credit_card_expire_date_year
Additional if Stripe is used:
- payment_credit_card_expiry (div for iframe)
- payment_credit_card_expiry_hidden
- payment_credit_card_network
You have to use these IDs!
Full default Stripe example:
<div>
<div id="payment_credit_card_owner_wrapper">
<div class="label">
<label for="payment_credit_card_owner">Karteninhaber/-in *</label>
</div>
<div class="field">
<input type="text" id="payment_credit_card_owner" name="payment[credit_card_owner]" autocomplete="off">
</div>
<div class="error" id="payment_credit_card_owner_error"></div>
</div>
<input type="hidden" id="payment_credit_card_token" name="payment[credit_card_token]">
<input type="hidden" id="payment_credit_card_network" name="payment[credit_card_network]">
<div id="payment_credit_card_number_wrapper">
<div class="label">
<label for="payment_credit_card_number">Kartennummer *</label>
</div>
<div class="field">
<div id="payment_credit_card_number"></div>
</div>
<div class="error" id="payment_credit_card_number_error"></div>
</div>
<div id="payment_credit_card_number_hidden_wrapper">
<div class="label">
<label for="payment_credit_card_number_hidden">Kartennummer *</label>
</div>
<div class="field">
<input type="text" id="payment_credit_card_number_hidden" name="payment[credit_card_number_hidden]" readonly="readonly">
</div>
<div class="error" id="payment_credit_card_number_hidden_error"></div>
</div>
<div id="payment_credit_card_secure_id_wrapper">
<div class="label">
<label for="payment_credit_card_secure_id">Prüfnummer *</label>
</div>
<div class="field">
<div id="payment_credit_card_secure_id"></div>
</div>
<div class="error" id="payment_credit_card_secure_id_error"></div>
</div>
<div id="payment_credit_card_secure_id_hidden_wrapper">
<div class="label">
<label for="payment_credit_card_secure_id_hidden">Prüfnummer *</label>
</div>
<div class="field">
<input type="text" id="payment_credit_card_secure_id_hidden" name="payment[credit_card_secure_id_hidden]" readonly="readonly">
</div>
<div class="error" id="payment_credit_card_secure_id_hidden_error"></div>
</div>
<div id="payment_credit_card_expiry_wrapper">
<div class="label">
<label for="payment_credit_card_expiry">Gültig bis *</label>
</div>
<div class="field">
<div id="payment_credit_card_expiry"></div>
</div>
<div class="error" id="payment_credit_card_expiry_error"></div>
</div>
<div id="payment_credit_card_expiry_hidden_wrapper">
<div class="label">
<label for="payment_credit_card_expiry_hidden">Gültig bis *</label>
</div>
<div class="field">
<input type="text" id="payment_credit_card_expiry_hidden" name="payment[credit_card_expiry_hidden]" readonly="readonly">
</div>
<div class="error" id="payment_credit_card_expiry_hidden_error"></div>
</div>
</div>
iframe-inputs
As you can see in the example above there is only a empty "payment_credit_card_number"-div, a "payment_credit_card_secure_id"-div and a "payment_credit_card_expiry"-div. Our plugin injects automatically the iframe-inputs into these divs.
Styling
As you don't have direct access to the inputs in the iframe, you have to style the surrounding divs e.g. "#payment_credit_card_number" like they were inputs.
creditCardFieldTemplate-Option
You can provide a "template" for the iframe-inputs, in general we recommend to use the "credit_card_owner"-field. If a template is given, our plugin sets the border to "0", the width to "100%" and the background to "none" of the iframe-inputs. It also copies the height and the font-styles of the template to the iframe-inputs.
This automatic style propagation takes place on window resize as well.
By default the template is set to "payment_credit_card_owner".
myForm = $("#form").fundraisingBoxForm({
hash: "{your_form_hash}",
creditCardFieldTemplate: "payment_credit_card_owner"
});
Custom fonts
For security reasons custom fonts are not possible in the iframe-inputs.
If you want to style the iframe-inputs directly, you can use the "creditCardStyle()"-function (see Functions). But we do not recommend this.
Recommendation
Use the "creditCardCopyStyleFromTemplate()"-function (see Functions) when you toggle your credit card fieldset to ensure the correct stylings.
Focus
It's a good manner to highlight the currently focused field, but highlighting the iframe-inputs is not easily possible. So our plugin sets a "focus"-class to the "payment_credit_card_number"-div, "payment_credit_card_secure_id"-div and "payment_credit_card_expiry"-div if the respective iframe-input is focused.
You can now consider this class for your design.
Our plugin considers the other way around as well: if a label is clicked, the respective iframe-input is focused.
Readonly "Hidden"-fields
After creating the credit card token, the credit card number and secure id are returned obfuscated. Example: the number 4567891234567890 will be returned as 456789******7890, the secure id is always just ***.
The "payment_credit_card_number_hidden", "payment_credit_card_secure_id_hidden" and "payment_credit_card_expiry_hidden" fields are required to show this obfuscated credit card data to the user. These fields should be readonly.
Our plugin hides automatically the wrappers of these fields in the first place. After sucessfully creating the token, these fields are filled with the obfuscated data and the wrappers will be shown. At the same time the "payment_credit_card_number_wrapper", "payment_credit_card_secure_id_wrapper" and "payment_credit_card_expiry_wrapper" will be hidden. The function "creditCardReset()" will reset and show the iframe-inputs and hides the "_hidden"-fields.
Create token
If the option "autoSubmit" is active (default) the plugin automatically call the "creditCardMakeToken()"-function (see Functions and trys to create the credit card token before sending the data to the payment session. If you disable autoSubmit you have to call the "creditCardMakeToken()" by yourself.
Simple credit card fields code example
<style>
input:focus, .focus {
border-color: #0f0;
}
</style>
<form id="form">
<div id="myFormFields"></div>
<input type="submit" value="submit">
</form>
<script src="path/to/jquery.min.js"></script>
<script src="https://secure.fundraisingbox.com/js/jquery.fundraisingbox.min.js"></script>
<script>
$(function() {
myForm = $("#form").fundraisingBoxForm({
hash: "{your_form_hash}",
creditCardFieldTemplate: "payment_credit_card_owner"
});
myForm.on("fundraisingBox:init", function(event) {
myForm.appendFieldRowsTo("#myFormFields", [
"payment_method",
"credit_card_owner",
"credit_card_token",
"credit_card_network",
"credit_card_number",
"credit_card_number_hidden",
"credit_card_secure_id",
"credit_card_secure_id_hidden",
"credit_card_expiry",
"credit_card_expiry_hidden"
]);
// reset the fields on payment method change
$("#payment_payment_method").change(function() {
if($(this).val() != "stripe_credit_card")
{
myForm.creditCardReset();
}
});
// some custom styling
myForm.on("fundraisingBox:creditCardReady", function() {
myForm.creditCardStyle("color", "#00f");
});
});
});
</script>