Skip to main content

Advanced integration topics

caution

The integration libraries and documentation for Yat are still in Alpha. They are not yet feature complete, and there are likely bugs in the implementation.

This guide will walk you through following advanced topics:

Discount codes#

If you are a y.at affiliate or partner, there are 2 ways of offering Yat discounts for your users:

  1. via a publicly available redemption code, or
  2. via an offer embedded in the app, and locked with a secret key

Redemption codes are used to claim discounts during the checkout flow at y.at.

Payment methods#

There are 2 payment methods which can be used for cart checkouts:

  1. Provider is directly managed by the y.at website to configure a payment provider, and is either Stripe or CoinbaseCommerce.
  2. Free was already described in Claiming a Yat with a promo code

Ordering and cart usage#

The code snippet below illustrates how you might implement payments via payment intents for users:

  1. The user adds a yat to their cart. In the example below we use a convenience endpoint that generates a random yat that is available for purchase.
  2. A new cart with the selected yat is created via the replace cart endpoint.
  3. The application obtains a token from Stripe for the user.
  4. We can then complete the checkout using the Stripe token.
  5. If the default payment is set in step 4, processing future payments is even simpler, using the Default payment method.
/** * Create new cart for user * @returns {Promise<*>} */ async function placeNewCart(items) {    let request = new yat.AddItemsCartRequest(items);    console.log("Sending add items cart request: ", request);    let cart = await api.cart().addItems(request);    console.log(`Created cart ${cart.id} with items `, cart.order_items.map((rec, i) => `${i+1}. ${rec.emoji_id} - ${rec.unit_price_in_cents}`));    return cart;}
async function main() {    try {        await api.login(email, password);        // Pick random yats        const emojis = await api.emojiID().random();        console.log("Random emoji suggestions:", emojis.result.map((rec, i) => `${i+1}. ${rec.emoji_id} - ${rec.price}`));        // Pick 2 yats from the middle and place into the cart        let items = emojis.result.map((rec) => new yat.AddItemsCartRequestItems(rec.emoji_id)).splice(2, 2);        await placeNewCart(items);
        // Checkout via payment intents. The user is given a payment intent ID which may be used to complete the purchase.        // Yat's Stripe public API key should be used for communication with Stripe        let result = await api.cart().checkout({ method: "Stripe"});        console.log(`Order is ${result.status}. Payment data: ${result.payment_method_data.payment_intent_id}.`);    } catch(err) {        console.log("Failed: ", err)    }}
// Main scriptmain().catch(res => {    console.log('Error:', JSON.stringify(res.body));}).then((res) => {    console.log("Bye!")});

This script produces output something along the lines of:

Random emoji suggestions: [  '1. โ™Ž๐Ÿ˜Žโ™ - 400',  '2. ๐Ÿ‘Ž๐Ÿ›ก๏ธ๐ŸŒฐ - 400',  '3. ๐Ÿ›๏ธโšพ๐Ÿ’ณ - 21000',  '4. ๐ŸŸ๏ธ๐Ÿ€๐ŸŽธ๐Ÿต - 400',  '5. ๐Ÿ˜๐Ÿ—„๏ธโœก๏ธ - 500',  '6. ๐Ÿจ๐Ÿ’๐Ÿ‰โšฝ - 10000',  '7. โ›ช๐ŸŒด๐Ÿœโ›ต - 9000',  '8. ๐Ÿฆ‰๐ŸŽ๐ŸŒฎ๐Ÿ’ฉ - 800',  '9. ๐Ÿ’ฐ๐Ÿฆ๐ŸŽฅ - 8500',  '10. โšฝ๐Ÿ”๐Ÿš€๐Ÿ‘€ - 10500']Sending add items cart request:  AddItemsCartRequest {  items: [    AddItemsCartRequestItems { emoji_id: '๐Ÿ›๏ธโšพ๐Ÿ’ณ' },    AddItemsCartRequestItems { emoji_id: '๐ŸŸ๏ธ๐Ÿ€๐ŸŽธ๐Ÿต' }  ]}Created cart aed099bd-f932-4e84-86dc-644c5fc13e74 with items  [ '1. ๐Ÿ›๏ธโšพ๐Ÿ’ณ - 10500', '2. ๐ŸŸ๏ธ๐Ÿ€๐ŸŽธ๐Ÿต - 400' ]Order is PendingPayment. Payment data: pi_3Js9jAE6aCXPXX5q18SRrRQE.Bye!

Using Stripe#

Yat uses Stripe as a payment provider for handling credit card payments. Stripe manages and stores all credit card and personally identifying information (PII), none of which is stored on y.at's servers.

To integrate card payments into a third-party application you need to obtain a Stripe API public key from the Yat integration team.

The following is a list of suggested resources for reading about using Stripe for payments: