Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
meta {
name: Check Customer Balances
type: http
seq: 7
}

get {
url: {{credytApiUrl}}/customers/{{customerId}}/wallet
body: none
auth: inherit
}

settings {
encodeUrl: true
timeout: 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
meta {
name: Create a Credit Asset
type: http
seq: 1
}

post {
url: {{credytApiUrl}}/assets
body: json
auth: inherit
}

body:json {
{
"code": "CREDIT",
"name": "Credits",
"precision": 0,
"symbol": "⭐",
"label": "CR",
"rates": [
{
"source": "USD",
"rate": 0.05
}
]
}
}

script:pre-request {
bru.setEnvVar("assetCode", req.getBody().code);
}

settings {
encodeUrl: true
timeout: 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
meta {
name: Create a Customer
type: http
seq: 4
}

post {
url: {{credytApiUrl}}/customers
body: json
auth: inherit
}

body:json {
{
"name": "{{$randomFullName}}",
"external_id": "{{customerExternalId}}",
"email": "{{$randomEmail}}",
"subscriptions": [
{
"return_url": "https://glitch.ai/account",
"failure_url": "https://glitch.ai/callbacks/credyt/failure",
"products": [
{
"code": "{{productCode}}"
}
]
}
]
}
}

script:pre-request {
const { v4 } = require('uuid');

const generateUuidWithoutHyphens = () => v4().replace(/-/g,"");

const externalId = `${generateUuidWithoutHyphens()}`;
bru.setVar("customerExternalId", externalId);
}

script:post-response {
if(res.status === 201){
const responseJson = res.getBody();

if (responseJson && responseJson.id) {
bru.setEnvVar("customerId", responseJson.id);
}
}
}

settings {
encodeUrl: true
timeout: 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
meta {
name: Create a Free Tier Product (Promotional)
type: http
seq: 3
}

post {
url: {{credytApiUrl}}/products
body: json
auth: inherit
}

body:json {
{
"name": "Free Tier Product",
"code": "free_tier_01",
"entitlements": [
{
"name": "Daily Reward",
"asset": "CREDIT",
"amount": 50,
"purpose": "promotion",
"refresh": {
"interval": "day",
"strategy": "expire_and_replace"
},
"accounting": {
"revenue_basis": 0.0,
"cost_basis": "auto"
}
}
],
"prices": [
{
"name": "Image Generation",
"type": "usage_based",
"billing_model": {
"type": "real_time"
},
"usage_calculation": {
"event_type": "image_generated",
"usage_type": "unit"
},
"pricing": [
{
"asset": "CREDIT",
"values": [
{
"unit_price": 5
}
]
}
]
}
],
"publish": true
}
}

script:post-response {
if(res.status === 201){
const responseJson = res.getBody();

if (responseJson && responseJson.id) {
bru.setEnvVar("freeProductId", responseJson.id);
bru.setEnvVar("freeProductCode", responseJson.code);
}
}
}

settings {
encodeUrl: true
timeout: 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
meta {
name: Create a Product with Entitlements
type: http
seq: 2
}

post {
url: {{credytApiUrl}}/products
body: json
auth: inherit
}

body:json {
{
"name": "Premium Plan",
"code": "premium_monthly_01",
"description": "Standard monthly subscription with included credit allowance.",
"entitlements": [
{
"name": "Monthly Credit Allowance",
"asset": "CREDIT",
"amount": 1000,
"purpose": "bundled",
"refresh": {
"interval": "month",
"strategy": "expire_and_replace"
},
"accounting": {
"revenue_basis": 0,
"cost_basis": "auto"
}
}
],
"prices": [
{
"name": "Monthly Subscription Fee",
"type": "fixed",
"billing_model": {
"type": "recurring",
"recurring": {
"interval": "month"
}
},
"pricing": [
{
"asset": "USD",
"values": [
{
"unit_price": 20
}
]
}
]
},
{
"name": "Image Generation",
"type": "usage_based",
"billing_model": {
"type": "real_time"
},
"usage_calculation": {
"event_type": "image_generated",
"usage_type": "unit"
},
"pricing": [
{
"asset": "CREDIT",
"values": [
{
"unit_price": 10
}
]
}
]
}
],
"publish": true
}
}

script:post-response {
if(res.status === 201){
const responseJson = res.getBody();

if (responseJson && responseJson.id) {
bru.setEnvVar("productId", responseJson.id);
bru.setEnvVar("productCode", responseJson.code);
}
}
}

settings {
encodeUrl: true
timeout: 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
meta {
name: Get Product Details
type: http
seq: 5
}

get {
url: {{credytApiUrl}}/products/{{productId}}
body: none
auth: inherit
}

settings {
encodeUrl: true
timeout: 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
meta {
name: Send Usage Events
type: http
seq: 6
}

post {
url: {{credytApiUrl}}/events
body: json
auth: inherit
}

headers {
Content-Type: application/json
}

body:json {
{
"customer_id": "{{customerId}}",
"events": [
{
"id": "{{$randomUUID}}",
"event_type": "image_generated",
"occurred_at": "{{$isoTimestamp}}",
"subject": "img_{{$randomUUID}}",
"description": "Image Generated"
}
]
}
}

settings {
encodeUrl: true
timeout: 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
meta {
name: Entitlements
seq: 2
}

auth {
mode: inherit
}