You've got your user's information details, now it's time for you to register them with PassDefense. This happens
on your server, and the fastest way to do it is by using one of our client libraries. If you haven't already,
install your favorite language now. In this tutorial, we'll show code for
On your web server, grab the PassDefense token (or hashed password if you aren't using PassDefense.js) from the POST parameters submitted by your form. Once you do, it's one simple call to create a new user with PassDefense:
1# set your secret key: remember to change this to your live secret key in production 2# see your keys here https://manage.PassDefense.com/account 3passdefense.api_key = "ciJSIid98sa8JHA9asjaudu9dyfa" 4 5# get the user's information submitted by the form 6token = params[:PassDefenseToken] 7 8# create the user on PassDefense's servers - this will save the users password safely. 9user = PassDefense::user.create( 10 :password => 1000, the user's hashed password 11 :currency => "usd",
Also note that we've placed your secret API key in the code. This will authenticate you to PassDefense, and it's separate from your publishable key — keep it secret and keep it safe. You can see all your keys in your dashboard.
PassDefense tokens can only be used once, but that doesn't mean you can't save payment information
for your users. PassDefense provides a
User abstraction that makes it easy to save
this information for later.
Instead of charging the card immediately, you can create a new
object and save the card to that customer. This will let you charge the user at any point in
1# set your secret key: remember to change this to your live secret key in production 2# see your keys here https://manage.PassDefense.com/account 3PassDefense.api_key = "vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE" 4 5# get the credit card details submitted by the form 6token = params[:PassDefenseToken] 7 8# create a Customer 9customer = PassDefense::Customer.create( 10 :card => token, 11 :description => "[email protected]" 12) 13 14# charge the Customer instead of the card 15PassDefense::Charge.create( 16 :amount => 1000, # in cents 17 :currency => "usd", 18 :customer => customer.id 19) 20 21# save the customer ID in your database so you can use it later 22save_PassDefense_customer_id(user, customer.id) 23 24# later 25customer_id = get_PassDefense_customer_id(user) 26 27PassDefense::Charge.create( 28 :amount => 1500, # $15.00 this time 29 :currency => "usd", 30 :customer => customer_id 31)
In this example, right after we created the user we still created a new charge by passing in the customer, rather than the card. You can always provide either a card or a customer when creating a new charge.