Skip to content

Commit

Permalink
update flow based on new open payments api
Browse files Browse the repository at this point in the history
  • Loading branch information
ionutanin committed Nov 3, 2023
1 parent 045b4e7 commit 037c229
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
44 changes: 32 additions & 12 deletions src/background/grantFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { tabs } from 'webextension-polyfill'

import { getAxiosInstance } from '@/background/requestConfig'

const KEY_ID = '530c7caf-47a2-4cbd-844e-b8ed53e5c0d7'
const KEY_ID = 'f9eb6bfe-26d2-46a8-88fd-b8b6c56132ad'
const PRIVATE_KEY =
'LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1DNENBUUF3QlFZREsyVndCQ0lFSU1xYkZodTlNZHpjNXZROXBoVDY0aGZ4Z0pRazM2TFVyR1VqL1cwbHRTWG0KLS0tLS1FTkQgUFJJVkFURSBLRVktLS0tLQo='
'LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1DNENBUUF3QlFZREsyVndCQ0lFSUgwcDgzZ2dmYTUyNUw1K1BJbkZ1SHoxUFdZQzRFKy9UTEl1R09NMFRMTXcKLS0tLS1FTkQgUFJJVkFURSBLRVktLS0tLQo='
const WM_PAYMENT_POINTER_URL = 'https://ilp.rafiki.money/web-monetization' // intermediarul

export class PaymentFlowService {
Expand All @@ -22,6 +22,7 @@ export class PaymentFlowService {
outgoingPaymentGrantToken: string
continuationRequestToken: string
interactRef: string
walletAddressId: string

amount: string

Expand All @@ -37,6 +38,7 @@ export class PaymentFlowService {

async initPaymentFlow() {
await this.getClientAuth()
await this.getWalletAddress()
await this.getIncomingPaymentUrlId()
await this.getQuoteGrant()
await this.getQuote()
Expand Down Expand Up @@ -76,10 +78,25 @@ export class PaymentFlowService {
this.clientAuthToken = response.data.access_token.value
}

async getWalletAddress() {
const response = await this.axiosInstance.get(
this.receivingPaymentPointerUrl,
this.getHeaders(this.clientAuthToken),
)

if (!response?.data?.id) {
throw new Error('No client auth')
} else {
this.walletAddressId = response.data.id
}
}

async getIncomingPaymentUrlId() {
const incomingPayment = await this.axiosInstance.post(
`${this.receivingPaymentPointerUrl}/incoming-payments`,
{},
new URL(this.receivingPaymentPointerUrl).origin + '/incoming-payments',
{
walletAddress: this.receivingPaymentPointerUrl,
},
this.getHeaders(this.clientAuthToken),
)

Expand Down Expand Up @@ -114,7 +131,9 @@ export class PaymentFlowService {

async getQuote() {
const payload = {
method: 'ilp',
receiver: this.incomingPaymentUrlId,
walletAddress: this.sendingPaymentPointerUrl,
debitAmount: {
value: '1000',
assetCode: 'USD',
Expand All @@ -123,7 +142,7 @@ export class PaymentFlowService {
}

const quote = await this.axiosInstance.post(
`${this.sendingPaymentPointerUrl}/quotes`,
new URL(this.sendingPaymentPointerUrl).origin + '/quotes',
payload,
this.getHeaders(this.quoteGrantToken),
)
Expand All @@ -136,17 +155,17 @@ export class PaymentFlowService {
}

async getOutgoingPaymentGrant() {
const receivingPaymentPointerDetails = await this.axiosInstance.get(
this.receivingPaymentPointerUrl,
)
console.log('receivingPaymentPointerDetails', receivingPaymentPointerDetails)
// const receivingPaymentPointerDetails = await this.axiosInstance.get(
// this.receivingPaymentPointerUrl,
// )
console.log('walletAddress id', this.walletAddressId)
const payload = {
access_token: {
access: [
{
type: 'outgoing-payment',
actions: ['create', 'read', 'list'],
identifier: this.sendingPaymentPointerUrl,
actions: ['list', 'list-all', 'read', 'read-all', 'create'],
identifier: this.sendingPaymentPointerUrl, // sendingPaymentPointerUrl
limits: {
debitAmount: {
value: '2000',
Expand All @@ -169,8 +188,9 @@ export class PaymentFlowService {
}

const outgoingPaymentGrant = await this.axiosInstance.post(
'https://auth.rafiki.money/',
'https://auth.rafiki.money',
payload,
this.getHeaders(this.clientAuthToken),
)

if (!outgoingPaymentGrant.data.interact.redirect) {
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4097,11 +4097,6 @@ interpret@^3.1.1:
resolved "https://registry.yarnpkg.com/interpret/-/interpret-3.1.1.tgz#5be0ceed67ca79c6c4bc5cf0d7ee843dcea110c4"
integrity sha512-6xwYfHbajpoF0xLW+iwLkhwgvLoZDfjYfoFNu8ftMoXINzwuymNLd9u/KmwtdT2GbR+/Cz66otEGEVVUHX9QLQ==

inversify@^6.0.2:
version "6.0.2"
resolved "https://registry.yarnpkg.com/inversify/-/inversify-6.0.2.tgz#dc7fa0348213d789d35ffb719dea9685570989c7"
integrity sha512-i9m8j/7YIv4mDuYXUAcrpKPSaju/CIly9AHK5jvCBeoiM/2KEsuCQTTP+rzSWWpLYWRukdXFSl6ZTk2/uumbiA==

is-arguments@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/is-arguments/-/is-arguments-1.1.1.tgz#15b3f88fda01f2a97fec84ca761a560f123efa9b"
Expand Down

0 comments on commit 037c229

Please sign in to comment.