Created
December 19, 2022 12:34
-
-
Save evalphobia/5d34180fc8e0c757ac28439bc8a58cd3 to your computer and use it in GitHub Desktop.
Check PayPal payment data from Transaction ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1122334455667788A | |
AABBCCDDEEFFGGHH1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"fmt" | |
"os" | |
"time" | |
"github.com/evalphobia/go-paypal-classic/client/transaction" | |
"github.com/evalphobia/go-paypal-classic/config" | |
) | |
func main() { | |
conf, err := getConfig() | |
if err != nil { | |
fmt.Printf("[ERROR] %s\n", err.Error()) | |
return | |
} | |
conf.SetAsProduction() | |
cli := transaction.New(conf) | |
txID, err := getTransactionID() | |
if err != nil { | |
fmt.Printf("[ERROR] %s\n", err.Error()) | |
return | |
} | |
api := transaction.TransactionSearch{ | |
StartDate: time.Date(2013, time.January, 1, 1, 0, 0, 0, time.UTC), | |
TransactionID: txID, | |
} | |
resp, err := api.Do(cli) | |
switch { | |
case err != nil: | |
fmt.Printf("[ERROR] %s\n", err.Error()) | |
return | |
case len(resp.Items) == 0: | |
fmt.Printf("[API ERROR] [%+v]\n", resp.BaseResponse) | |
return | |
} | |
for i, v := range resp.Items { | |
if v.TransactionID != txID { | |
continue | |
} | |
fmt.Printf("[#%d] Date:%s, Type:%s, Email:%s, Status:%s\n", i, v.Timestamp.Format("2006-01-02"), v.Type, v.Email, v.Status) | |
return | |
} | |
fmt.Printf("[ERROR] Cannot find by the tx id: [%s]\n", txID) | |
} | |
func getTransactionID() (string, error) { | |
id := os.Getenv("PAYPAL_TRANSACTION_ID") | |
if id == "" { | |
return "", errors.New("PAYPAL_TRANSACTION_ID is empty") | |
} | |
return id, nil | |
} | |
func getConfig() (*config.Config, error) { | |
u := os.Getenv("PAYPAL_API_USER") | |
if u == "" { | |
return nil, errors.New("PAYPAL_API_USER is empty") | |
} | |
p := os.Getenv("PAYPAL_API_PASSWORD") | |
if p == "" { | |
return nil, errors.New("PAYPAL_API_PASSWORD is empty") | |
} | |
s := os.Getenv("PAYPAL_API_SIGNATURE") | |
if s == "" { | |
return nil, errors.New("PAYPAL_API_SIGNATURE is empty") | |
} | |
return &config.Config{ | |
User: u, | |
Pass: p, | |
Signature: s, | |
Version: 123, | |
}, nil | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# export PAYPAL_API_USER=... | |
# export PAYPAL_API_PASSWORD=... | |
# export PAYPAL_API_SIGNATURE=... | |
go build . | |
chmod +x ./paypal_search | |
for line in `cat list.txt`; do | |
PAYPAL_TRANSACTION_ID=$line ./paypal_search | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment