PayPal 거래를 Google 스프레드시트로 가져오는 방법

게시 됨: 2022-06-16

PayPal transactions in Google Sheets

이 자습서에서는 Google Apps Script를 사용하여 PayPal 거래를 Google 스프레드시트로 가져오는 방법을 보여줍니다. 표준 PayPal 결제, 정기 구독 결제, 기부 또는 환불 및 지불 거절을 Google 스프레드시트로 가져오도록 선택할 수 있습니다.

데이터를 Google 스프레드시트로 가져오면 CSV 파일로 내보내고 Quickbooks 회계 소프트웨어로 가져올 수 있습니다. 인도의 Tally 사용자는 Google Sheets의 PayPal 거래를 XML 형식으로 내보내고 Tally로 일괄 가져올 수 있습니다.

참조: Google Forms로 PayPal 자동화

Google 스프레드시트에서 PayPal 거래 가져오기

이 예에서는 PayPal을 통해 기부한 기부자 목록을 Google 스프레드시트로 가져옵니다.

1. PayPal 내에서 API 자격 증명 만들기

PayPal 개발자 대시보드(developer.paypal.com)에 로그인하고 라이브 모드에서 새 앱을 만듭니다. 앱 이름 Transaction Importer for Google Sheets 지정하고 앱 만들기 버튼을 클릭합니다.

PayPal은 이후 단계에서 필요한 클라이언트 ID 및 클라이언트 비밀 키를 생성합니다. 라이브 앱 설정 섹션에서 Transaction Search 옵션을 선택하고 다른 모든 옵션은 끄십시오. API 키가 트랜잭션을 나열하기만 하고 다른 기능은 없기를 원하기 때문입니다. 계속하려면 저장을 클릭하세요.

Paypal Account Credentials

2. Google 스프레드시트 프로젝트 만들기

sheets.new 로 이동하여 새 Google 시트를 만듭니다. 확장 프로그램 메뉴로 이동하고 Apps Script를 선택하여 Apps Script 편집기를 엽니다.

편집기에서 코드를 복사하여 붙여넣습니다. 거래 코드를 자신의 것으로 교체하는 것을 잊지 마십시오. PayPal 구독에는 T0002 , 기부금 지불에는 T0014 , PayPal 환불 및 지불 거절에는 T1107 을 사용할 수 있습니다.

/* @OnlyCurrentDoc */ comment는 현재 Google 시트 내에서만 코드를 실행하고 Google 드라이브의 다른 스프레드시트에 액세스할 필요가 없도록 Google Apps Script에 지시하는 Google Apps Script 주석입니다.

 /* @OnlyCurrentDoc */ /* Author: digitalinspiration.com */ const TRANSACTION_TYPE = 'T0001' ; // Enter your own PayPal Client ID and Client Secret key const PAYPAL_CLIENT_ID = '<YOUR_PAYPAL_CLIENT_ID>' ; const PAYPAL_CLIENT_SECRET = '<YOUR_PAYPAL_CLIENT_SECRET>' ; // Enter start and end dates in the format YYYY-MM-DD const START_DATE = '2022-03-01' ; const END_DATE = '2022-03-15' ; // Generate the PayPal access token const getPayPalAccessToken_ = ( ) => { const credentials = ` ${ PAYPAL_CLIENT_ID } : ${ PAYPAL_CLIENT_SECRET } ` ; const headers = { Authorization : ` Basic ${ Utilities . base64Encode ( credentials ) } ` , Accept : 'application/json' , 'Content-Type' : 'application/json' , 'Accept-Language' : 'en_US' , } ; const options = { method : 'POST' , headers , contentType : 'application/x-www-form-urlencoded' , payload : { grant_type : 'client_credentials' } , } ; const request = UrlFetchApp . fetch ( 'https://api.paypal.com/v1/oauth2/token' , options ) ; const { access_token } = JSON . parse ( request ) ; return access_token ; } ; // Append the query parameters to the PayPal API URL const buildAPIUrl_ = ( queryParams ) => { const baseUrl = [ ` https://api-m.paypal.com/v1/reporting/transactions ` ] ; Object . entries ( queryParams ) . forEach ( ( [ key , value ] , index ) => { const prefix = index === 0 ? '?' : '&' ; baseUrl . push ( ` ${ prefix } ${ key } = ${ value } ` ) ; } ) ; return baseUrl . join ( '' ) ; } ; // Fetch the list of PayPal transaction const fetchTransactionBatchFromPayPal = ( queryParams ) => { const options = { headers : { Authorization : ` Bearer ${ getPayPalAccessToken_ ( ) } ` , 'Content-Type' : 'application/json' , } , } ; const request = UrlFetchApp . fetch ( buildAPIUrl_ ( queryParams ) , options ) ; const { transaction_details , total_pages } = JSON . parse ( request ) ; return { transaction_details , total_pages } ; } ; // Extract the transaction details including the transaction ID, // donation amount, transaction date and buyer's email and country code const parsePayPalTransaction_ = ( { transaction_info , payer_info } ) => [ transaction_info . transaction_id , new Date ( transaction_info . transaction_initiation_date ) , transaction_info . transaction_amount ?. value , transaction_info . transaction_note || transaction_info . transaction_subject || '' , payer_info ?. payer_name ?. alternate_full_name , payer_info ?. email_address , payer_info ?. country_code , ] ; const fetchPayPalTransactions_ = ( ) => { const startDate = new Date ( START_DATE ) ; const endDate = new Date ( END_DATE ) ; startDate . setHours ( 0 , 0 , 0 , 0 ) ; endDate . setHours ( 23 , 59 , 59 , 999 ) ; const transactions = [ ] ; const params = { start_date : startDate . toISOString ( ) , end_date : endDate . toISOString ( ) , page_size : 100 , transaction_type : TRANSACTION_TYPE , fields : 'transaction_info,payer_info' , } ; for ( let page = 1 , hasMore = true ; hasMore ; page += 1 ) { const response = fetchTransactionBatchFromPayPal ( { ... params , page } ) ; const { transaction_details = [ ] , total_pages } = response ; transaction_details . map ( parsePayPalTransaction_ ) . forEach ( ( e ) => transactions . push ( e ) ) ; hasMore = total_pages && total_pages > page ; } return transactions ; } ; // Import the transactions from PayPal and write them to the active Google Sheet const importTransactionsToGoogleSheet = ( ) => { const transactions = fetchPayPalTransactions_ ( ) ; const { length } = transactions ; if ( length > 0 ) { const sheet = SpreadsheetApp . getActiveSheet ( ) ; sheet . getRange ( 1 , 1 , length , transactions [ 0 ] . length ) . setValues ( transactions ) ; const status = ` Imported ${ length } PayPal transactions into Google Sheets ` ; SpreadsheetApp . getActiveSpreadsheet ( ) . toast ( status ) ; } } ;

3. PayPal 가져오기 기능 실행

스크립트 편집기 내에서 실행 버튼을 클릭하여 PayPal에서 거래를 가져옵니다. PayPal API에 연결하고 사용자를 대신하여 Google 스프레드시트에 데이터를 쓸 수 있는 권한이 필요하므로 스크립트를 승인해야 할 수 있습니다.

그게 다야 선택한 날짜 범위에 가져올 PayPal 거래가 있는 경우 스크립트가 실행되고 거래가 Google 스프레드시트로 가져옵니다.

Run PayPal Importer

튜토리얼의 다음 부분에서는 Google Sheets에서 Tally 회계 소프트웨어로 가져오기 위해 PayPal 거래를 XML 파일로 내보내는 방법을 배웁니다.

참조: Google 스프레드시트에서 PayPal 인보이스 보내기