Skip to content
Snippets Groups Projects
create-payment-link.sh 936 B
Newer Older
  • Learn to ignore specific revisions
  • #!/usr/bin/env bash
    
    set -euo pipefail
    
    KEY=$1
    shift
    
    
    PRODUCT_ID=$(
        curl https://api.stripe.com/v1/products \
    	 -u "${KEY}:" \
    	 -d "name=30 GiB-months" \
    	 -d "description=30 GiB-months of Private.Storage storage × time" \
    	 -d "statement_descriptor=PRIVATE STORAGE" \
    
    	jp --unquoted id
    	  )
    
    echo "Product: $PRODUCT_ID"
    
    PRICE_ID=$(
        curl https://api.stripe.com/v1/prices \
    	 -u "${KEY}:" \
    	 -d "currency=USD" \
    	 -d "unit_amount=650" \
    	 -d "tax_behavior=exclusive" \
    	 -d "product=${PRODUCT_ID}" |
    	jp --unquoted id
    	)
    
    echo "Price: $PRICE_ID"
    
    LINK_URL=$(
        curl https://api.stripe.com/v1/payment_links \
    	 -u "${KEY}:" \
    	 -d "line_items[0][price]=${PRICE_ID}" \
    
    	 -d "line_items[0][quantity]=1" \
    	 -d "after_completion[type]"=redirect \
    	 -d "after_completion[redirect][url]"="https://${DOMAIN}/payment/success" |
    
    
    echo "Payment link: $LINK_URL"