How to use it?

1. First, include the library

Add this line before the </body> tag.

<script src="https://sdk.rebill.to/rebill.min.js"></script>

2. Initialize Library

The parameters apiUrl, orgId and planId are required in order to initialize the library.

const rebill = new Rebill({ apiUrl: 'https://api.rebill.to/v1/', orgId: '9d37db8b-6ab7-4db0-83d4-f6785afc44ba', planId: 1, callbackUrl: 'https://rebill.to' });

3. Add properties to the subscription that would be created.

You may add data using the methods setCustomer(customer), setTransaction(transaction), setRecipients(recipients), setCallbackUrl(callbackUrl) and setItems(items)

rebill.setCustomer({ firstName: "John", lastName: "Eagle", email: "john@test.com", vat_type: "DNI", vatID_number: 12345678, });

4. Open the PopUp

There are two ways to open the pop up:

const button = document.getElementById('button'); rebill.setButton(button);

when the button is pressed, a payment window (pop-up) will open.

or by simply, calling this method will open the window:

rebill.openPopup();

5. Declare callbacks

If you wish to set callback functions such as if the payment fails, or succeed you must use this methods:

  • onProcessSuccess(callback: (subsciption) => {})
  • onProcessFailed(callback: (error) => {})
rebill.onProcessSuccess(subscription => { console.log('Suscripción creada correctamente'); console.log('Subscription data', subscription); }); rebill.onProcessFailed(error => { console.log('Oh, something went wrong!', error); });

Métodos

Constructor

new Rebill(data)

Parameters

  • data: it is the object where all the required info is defined.

Set a payment Flow: with this SDK you may either process a unique one-time payment or create a new subscription. Therefore you can call these two methods depending on the function you want to achieve:

setNewSubscriptionFlow()

Defines that the flow being used will create a new subscription. It is the default process.

How to use it

rebill.setNewSubscriptionFlow();

setOneTimePaymentFlow()

Defines that the flow being used will create a one-time payment. It is the default process. Therefore there won't be any plan or subscription data related.

How to use it

rebill.setOneTimePaymentFlow();

setUpdateCardFlow(updateCardData)

Defines that the flow being used will update a card.

How to use it

rebill.setUpdateCardFlow({ customerId: 10, cardId: 1, token: '<user-token>' });

Parameters

updateCardData: defined the information required to update a card.

  • customerId (Number): Required. Rebill's customer id of the card owner.
  • Id (Number): Required. Card id to be updated.
  • Token (String): Required. Acces Token of the user with access to the card.

onProcessSuccess(callback)

Registers a callback to be executed when a subscription has been successfully created. onSubscriptionCreated is an alias for this method.

rebill.onProcessSuccess(suscripcion => { console.log(`Suscripcion con ID '${suscripcion.id}' creada correctamente.`); });

Parámetros

  • callback: a function that receives a parameter in which the data of the created subscription is assigned.

onProcessFailed(callback)

Registers a callback to be executed when an error occurs when creating the subscription. onSubscriptionFailed is an alias for this method.

rebill.onProcessFailed(error => { console.log(`El siguiente error ocurrió creado la suscripción`, error); });

Parameters:

  • error: a function that receives a parameter in which the error is assigned when trying to create a subscription.

setCustomer(customer)

Assign the client corresponding to the subscription. If the customer field is specified in the constructor, this method runs automatically.

Uso

rebill.setCustomer({ firstName: "John", lastName: "Test", email: "john@test.com", vat_type: "DNI", vatID_number: 12345678, });

Parámetros

  • customer: An object that contains a customer's information.

setRecipients(recipients)

Assign the recipients for the subscription. If the recipient's field is specified in the constructor, this method runs automatically.

rebill.setRecipients([ { type: "PERSON", name: "John", lastName: "Test", email: "test@test.com", gender: "Masculino", phone_areacode: "58", phone_number: "1234567890", birthday: "1994-03-22 04:00:00", vat_type: "CUIL", vatID_number: "1234567890" } ]);

Parámetros

  • recipients: An array containing objects with information about people or objects.

setTransaction(transaction)

Assign additional data about the transaction corresponding to the subscription. If the transaction field is specified in the constructor, this method runs automatically.

rebill.setTransaction({ referral_code: "abc123", external_reference: "abc" });

Parameters

  • transaction: An object with information about the transaction.

setCallbackUrl(url)

Assign a url to redirect after creating a subscription. If the callbackUrl field is specified in the constructor, this method runs automatically.

rebill.setCallbackUrl('https://rebill.to');

Parameters

  • url: A string containing the url to redirect.

setItems(items)

Assign an array of objects to save along with the subscription, these objects do not have a definite structure so they can contain any personality information. If the items field is specified in the constructor, this method runs automatically.

rebill.setItems([ { name: 'test', type: 'test', value: 123 } ]);

Parameters

  • items: An arrangement of objects with item information.
Did this answer your question?