This example shows a code implementation of a demo pay-with-tweet external payment gateway. This demo is built with Commerce Layer external gateways API and Twitter API. The idea is that when a customer purchases from your store, they’re prompted to make a tweet with a predefined text that includes their order number. The external payment gateway then reads the Twitter API for the tweet and authorizes the order if the tweet is found—good for peer-to-peer publicity/marketing in spaces like conferences. To get started, kindly read this comprehensive tutorial on our blog.
- Rename the
.env.example
file to.env
and add your valid credentials, like so:
CL_SHARED_SECRET=""
CL_TWITTER_ID=""
TW_BEARER_TOKEN=""
- Start the local server in development mode:
pnpm dev
- Start a ngrok HTTP tunnel listening for HTTP/HTTPS traffic on port 9000:
ngrok http 9000
- Create a new payment gateway using the CLI:
cl create external_gateways -a \
name="Pay With Tweet"
- Create a payment method:
cl create payment_methods -a \
payment_source_type="ExternalPayment" \
currency_code="USD" \
price_amount_cents=0 -r \
market="FlqxGhKrFg" \
payment_gateway="BkXMMsBDGa"
- Create an external payment:
cl create external_payments -a \
payment_source_token="testTokeN1234"
- Create and place an order:
cl update orders GHrQkxDVPS -a _place=true