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 codesIf you are a y.at affiliate or partner, there are 2 ways of offering Yat discounts for your users:
- via a publicly available redemption code, or
- 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 methodsThere are 2 payment methods which can be used for cart checkouts:
Provider
is directly managed by the y.at website to configure a payment provider, and is eitherStripe
orCoinbaseCommerce
.Free
was already described in Claiming a Yat with a promo code
#
Ordering and cart usageThe code snippet below illustrates how you might implement payments via payment intents for users:
- 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.
- A new cart with the selected yat is created via the replace cart endpoint.
- The application obtains a token from
Stripe
for the user. - We can then complete the checkout using the
Stripe
token. - If the default payment is set in step 4, processing future payments is even simpler, using the
Default
payment method.
- Javascript / NodeJs
- Android / Kotlin
- iOS / Swift 5
/** * 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!")});
๐ง COMING SOON ๐ง
๐ง COMING SOON ๐ง
This script produces output something along the lines of:
- Javascript / NodeJs
- Android / Kotlin
- iOS / Swift 5
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!
๐ง COMING SOON ๐ง
๐ง COMING SOON ๐ง
#
Using StripeYat 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:
- Development quickstart https://stripe.com/docs/development
- Creating a card token https://stripe.com/docs/api/tokens/create_card
- Testing stripe payments https://stripe.com/docs/testing
- API Keys https://stripe.com/docs/keys