Skip to content

Latest commit

 

History

History
92 lines (58 loc) · 3.06 KB

4_payment_methods.md

File metadata and controls

92 lines (58 loc) · 3.06 KB

Payment Methods

The first thing you'll need to do is add a payment method. You will get a payment method token from the payment processor's Javascript library. See the payment processors docs for how to setup their Javascript.

Assigning A Payment Method

With Pay, you can simply assign the payment method token before making a charge or subscription.

Pay will attempt to save an API request by creating a Customer and assigning PaymentMethod in the same request if a payment_method_token is set.

@user.payment_processor.payment_method_token = params[:payment_method_token]
@user.payment_processor.charge(15_00)

The payment method will be set as the default, so future payments do not need to collect a payment method.

If a customer would like to purchase and provide a new payment method, you may still assign a payment_method_token before purchasing.

Updating the default Payment Method

To update the default payment method on file, you can use update_payment_method:

@user.payment_processor.update_payment_method(params[:payment_method_token])

This will add the payment method via the API and mark it as the default for future payments.

Paddle Billing

For updating payment method details on Paddle, a transaction ID is required. This can be generated by using

subscription = @user.payment_processor.subscription(name: "plan name")
transaction  = subscription.payment_method_transaction

Once you have a transaction ID, you can then pass that through to Paddle.js like so

<a href="#"
  class="paddle_button"
  data-display-mode="overlay"
  data-theme="light"
  data-locale="en"
  data-transaction-id="<%= transaction.id %>"
>
	Update Payment Details
</a>

This will then open the Paddle overlay and allow the user to update their payment details.

For more information, see the Paddle documentation

Paddle Classic

Paddle uses an Update Payment Details URL for each customer which allows them to update the payment method. This is stored on the Pay::Subscription record for easy access.

@user.payment_processor.subscription.paddle_update_url

You may either redirect to this URL or use Paddle's Javascript to render as an overlay or inline.

Adding other Payment Methods

You can also add a payment method without making it the default.

@user.payment_processor.add_payment_method(params[:payment_method_token], default: false)

Importing Payment Methods

Paddle Billing

If a Paymment Method doesn't exist in Pay, then you can use the following method to create it from Paddle Billing:

It takes a Pay::Customer and a Paddle Transaction ID as arguments.

Pay::PaddleBilling::PaymentMethod.sync_from_transaction pay_customer: @user.payment_processor, transaction: "txn_abc123"

If a Payment Method already exists with the token, then it will be updated with the latest details from Paddle.

Next

See Charges