โถ๏ธBuy Button SDK
(see end of document for sdk-v2 )
Add the SDK
You can add it in a script tag.
<script src="https://admin.lyzi.fr/assets/buy-button/sdk.js" defer></script>
now you can access the SDK through window.lyziBuyButton
angular project load in angular.json file
"architect": { "build": { .... "scripts": [ "src/assets/buy-button/sdk.js" ], },
then load using โdeclare var lyziBuyButton: any;โ in your component
Using the SDK
init Before using availables methods, you should init the SDK at first or, some methods will not work properly.
window.lyziBuyButton.init({ โฆconfig }, elementSelector) available config
variable
type
default value
required
note
env
enum string
local
no
available value: โlocalโ, โdevelopโ, โstagingโ, โproductionโ
buttonId
string
undefined
yes
buttonName
string
null
no
orderRef
string
null
no
currency
string
eur
no
base currency
price
string
null
no
buttonAppUrl
string
http://localhost:4200/buy-button/landing
no
donโt include any params on this var
callbackUrl
string
null
no
page redirect after payment succeed
goods
Object
undefined
yes
object refer to https://api-dev.lyzi.fr/docs/#api-Conversions-Request_conversion
example:
<script>
window.lyziBuyButton.init({
buttonId: '640539aba7ab8755cace1edf',
orderRef: 'CURRENTORDER-FP-2023',
price: 0.1,
buttonName: 'overided button',
callbackUrl: 'https://webhook.site/19cab1dd-f578-4e17-a937-1af14434ad66',
env: 'local',
goods: {
goodsName: 'yolo good',
goodsCategory: '1000',
goodsType: '01'
}
}, document.getElementById('test-lyzi'));
</script>
generating html code snippet window.lyziBuyButton.generateSnippet({ โฆconfig })
variable
type
default value
required
note
type
string
default
no
available value: โdefaultโ
display
string
popup
no
available value: โpopupโ
return value
{ modalSnippet: (HTML Tag)(DEPRECATED), modalJsSnippet: (HTML Tag), buttonSnippet: (HTML Tag),
cssHrefSnippet: (HTML Tag) }
get the transaction code
window.lyziBuyButton.getTransactionCode()
MISC
Overriding stored button data Every button that is stored in db can be overridden by the url query params. you shouldnโt override the button id, if you override it then the button will not work.
variable
type
default value
required
note
itemRef
string
button stored db data
no
orderRef
string
button stored db data
no
price
number
button stored db data
no
currency
string
button stored db data
no
currency code. e.g: eur,btc,xmr, etcโฆ
You can get all the status variable in the call back url Exemple : The payment from lyzi button url will redirected to callback url with some data
https://webhook.site/1b7626e0-0924-4132-9286-f255d3e2d16b?_id=651adbdce86e79001da42a64&goods[_id]=651adbdce86e79001da42a65&goods[goodsCategory]=Z000&goods[goodsName]=anu&goods[goodsType]=02&goods[referenceGoodsId]=25356565600097006179732745012310023902000010&fromAsset=EUR&toAsset=USDT&fromAmount=0.1&toAmount=0.10803996&exchangeInfo[_id]=651adbdce86e79001da42a66&exchangeInfo[symbol]=EURUSDT&exchangeInfo[price]=1.04893162&code=25356565600097006179732745012310023902000010&shortCode=28LF46A9&status=PAID&expireTime=1696259344889&createdAt=2023-10-02T15%3A03%3A56.406Z&updatedAt=2023-10-02T18%3A13%3A34.292Z&__v=0&payer[_id]=649421dfa92ff3001d4ed6d8&payer[firstName]=Lyzi&payer[lastName]=Tester&payer[email]=testuser%40lyzi.fr&payer[phoneNumber]=12345678&payer[cashbackBalance]=0&confirm[_id]=651adbe1e86e79001da42ad7&confirm[order]=651adbdce86e79001da42a64&confirm[type]=WEBSITE&confirm[merchant][_id]=65157c845b85c20dd565d211&confirm[merchant][url]=https%3A%2F%2Flyzi.fr&confirm[merchant][user]=62bc1c651a8eda001c72845c&confirm[merchant][__v]=0&confirm[merchant][id]=65157c845b85c20dd565d211&confirm[createdAt]=2023-10-02T15%3A04%3A01.378Z&confirm[updatedAt]=2023-10-02T15%3A04%3A01.378Z&confirm[__v]=0&confirm[id]=651adbe1e86e79001da42ad7&id=651adbdce86e79001da42a64&extraParams=lyzi%7C651ae9e2c5f580d4dad417f9
check transaction status by api with Api keys (mandatory)
curl --location --request GET 'https://api-dev.lyzi.fr/api/confirm_conversion/status/order/62790783694dec2196f0bbda~820'
Implementation sample
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="http://localhost:4200/assets/buy-button/sdk.js"></script>
<a id="test-lyzi">Payer</a>
<script>
window.lyziBuyButton.init({
buttonId: '640539aba7ab8755cace1edf',
orderRef: 'CURRENTORDER-FP-2022101001',
price: 0.1,
callbackUrl: 'https://webhook.site/1f17c789-f035-4d72-8f9e-2cf2908d5a2e',
env: 'local',
goods: {
goodsName: 'yolo good',
goodsCategory: '1000',
goodsType: '01'
}
}, document.getElementById('test-lyzi'));
</script>
</body>
</html>
if you want to separate return, cancel and callback url functionality, now it possible by our sdk-v2. here is code implementation sample
if you pass of those 3 url params,
we will send webhook to callbackUrl by post method
redirect to cancelUrl if user cancel the payment
redirect to returnUrl after payment succeed
but if you still prefer use only callbackUrl, youโll also get all those 3 above in your callbackUrl
Last updated