@onramper/moonpay-adapter
TypeScript icon, indicating that this package has built-in type declarations

1.6.19 • Public • Published

Usage

It works like a fetch mock:

import processMoonpayStep, { moonpayUrlRegex } from '@onramper/moonpay-adapter'

const method = step.type === 'file' ? 'PUT' : 'POST'
const body = step.type === 'file' ? data as File : JSON.stringify(data)

const nextStepType = step.url.split('/')[5]
let nextStep: FetchResponse;
if (isMoonpayStep(step.url) && nextStepType !== "iframe") {
    nextStep = await processMoonpayStep(step.url, { method, headers, body });
} else {
    nextStep = await fetch(step.url, { method, headers, body })
}
return processResponse(nextStep)

Note

Due to Moonpay's cookie policy all operations must be performed from the same origin, meaning that the sandbox that handles credit card payments requires a special workaround that doesn't fit our API response model. Namely, the response from the sandbox must be further processed by client-side code before the next step is provided, so the following code is needed:

import { finishCCTransaction, baseCreditCardSandboxUrl } from '@onramper/moonpay-adapter'

const receiveMessage = async (event: MessageEvent) => {
  if (event.origin !== baseCreditCardSandboxUrl)
    return;
  if (event.data.type) {
    replaceScreen(event.data)
  } else if (event.data.transactionId) {
    const returnedNextStep = await finishCCTransaction(event.data.transactionId, event.data.ccTokenId);
    replaceScreen(returnedNextStep)
  } else {
    setError('Unknown error. Please, contact help@onramper.com and provide the following info: ' + nextStep.url)
  }
}
window.addEventListener("message", receiveMessage);

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.6.1914latest

Version History

VersionDownloads (Last 7 Days)Published
1.6.1914
1.6.181
1.6.171
1.6.160
1.6.151
1.6.140
1.6.131
1.6.120
1.6.110
1.6.101
1.6.90
1.6.80
1.6.70
1.6.60
1.6.51
1.6.40
1.6.30
1.6.20
1.6.10
1.6.00
1.5.30
1.5.20
1.5.10
1.5.01
1.4.181
1.4.170
1.4.160
1.4.150
1.4.140
1.4.131
1.4.120
1.4.100
1.4.90
1.4.80
1.4.71
1.4.60
1.4.50
1.4.40
1.4.30
1.4.20
1.4.10
1.4.01
1.3.02
1.2.30
1.1.30
1.1.20
1.1.10
1.1.01
1.0.00

Package Sidebar

Install

npm i @onramper/moonpay-adapter

Weekly Downloads

28

Version

1.6.19

License

MIT

Unpacked Size

191 kB

Total Files

90

Last publish

Collaborators

  • dmitry-onramper
  • gihanrcg-onramper
  • chamithm
  • corollari
  • 0xsalah