私はこの方法でそれを取得しています:
let options = {
method: 'post', headers: {'content-type':'application/json','Access-Control-Allow-Credentials':true},
auth:{'username':process.env.PAYPALID,'password':process.env.PAYPALPASSWORD},
url: 'https://api.paypal.com/v1/oauth2/token',
data: 'grant_type=client_credentials',
}
axios(options).then((response)=>{let paypaltoken=response.data.access_token
axios.get('https://api.paypal.com/v1/payments/billing-agreements/'+agreementid+'/transactions?start_date=2018-01-01&end_date=2019-07-07', { headers: { 'Authorization':'Bearer '+paypaltoken, 'Content-Type':'application/json', } })
.then((transaction)=>{console.log(transaction.data)})
.catch(err => {console.error(err);console.log('err: '+JSON.stringify(err)); res.send (err) })
})
.catch(err => {console.error(err);console.log('err: '+JSON.stringify(err)); res.send (err) })
次に、transaction.dataだけを取得すると、一連のトランザクションオブジェクトが取得されます。このオブジェクトは、トランザクションが正常に実行された場合、つまりキャンセルされていない場合にのみstatus
==Completed
になるため、計画を制御するために最後のオブジェクトを確認してください。status
is ==の場合Canceled
、契約はもうアクティブではないことがわかります。
毎月の支払いを受け取る場合のもう1つの方法は、最初の日付を「now()」から2か月に設定し、2番目の日付を「now()」に設定することです。トランザクションが発生しない場合、ステータスはアクティブではない可能性がありますが、再確認してください。クレジットカードに問題がある可能性がランダムにあります。その場合status
、== todelayed
か何か他のものである可能性があると思いますが、それをテストする可能性がなかったので、わかりません。このアイデアは、この質問と、CyrilALFAROと同様に私の感謝に値する相対的な2番目の回答から生まれました。
場合によっては、リクエスト'Access-Control-Allow-Credentials':true
に他のまたは同様のものではなく、ヘッダーを追加する必要がある場合があることに注意してください。withCredentials: true