Comments (3)
I have an example in README, did you try it, and what kind of error do you have, also please post your code in the issue.
// paymentID is returned via return_url
paymentID := "PAY-17S8410768582940NKEE66EQ"
// payerID is returned via return_url
payerID := "7E7MGXCWTTKK2"
executeResult, err := c.ExecuteApprovedPayment(paymentID, payerID)
from paypal.
@plutov sorry for the late response
so this is the endpoint im using to start the transaction
func paypalDonationPost(c *gin.Context) {
// Create a client instance
client, err := paypalsdk.NewClient(appConfig.Paypal.ClientID, appConfig.Paypal.Secret, paypalsdk.APIBaseSandBox)
if err != nil {
log.Println(err.Error())
getSiteInfo(c).Session.AddFlash("Unable to process donation at this time")
c.Redirect(302, "/donate")
}
// When you will have authorization_code you can get an access_token
_, err = client.GetAccessToken()
if err != nil {
log.Println("access token", err.Error())
getSiteInfo(c).Session.AddFlash("Unable to process donation at this time")
c.Redirect(302, "/donate")
}
//client.SetAccessToken(accessToken.Token)
log.Println(d)
// Now we can create a paypal payment
redirectURI := fmt.Sprint("https://example.com/donate/confirm/?transactionID=", d.ID)
cancelURI := fmt.Sprint("https://example.com/donate/cancel/?transactionID=", d.ID)
p := paypalsdk.Payment{
Intent: "sale",
Payer: &paypalsdk.Payer{
PaymentMethod: "paypal",
},
Transactions: []paypalsdk.Transaction{{
ItemList: &paypalsdk.ItemList{
Items: []paypalsdk.Item{
{
Name: "Donation to ",
SKU: "Donation to",
Currency: "USD",
Price: amount,
Quantity: 1,
},
},
},
Amount: &paypalsdk.Amount{
Total: amount,
Currency: "USD",
},
Description: "My Payment",
Custom: "Some custom text and all",
}},
RedirectURLs: &paypalsdk.RedirectURLs{
ReturnURL: redirectURI,
CancelURL: cancelURI,
},
}
res, err := client.CreatePayment(p)
if err != nil {
fmt.Fprint(c.Writer, err.Error())
} else {
log.Print(res.Links[0])
log.Print(res.Links[1])
c.Redirect(302, res.Links[1].Href)
}
}
and after the user goes through the payment process and accepts paypal routes back to this endpoint
func PaymentSuccess(c *gin.Context) {
uID, _ := strconv.Atoi(c.Param("transactionID"))
// paymentID is returned via return_url
paymentID := c.Param("paymentId")
// payerID is returned via return_url
payerID := c.Param("PayerID")
client, err := paypalsdk.NewClient(appConfig.Paypal.ClientID, appConfig.Paypal.Secret, paypalsdk.APIBaseSandBox)
log.Println(uID, paymentID, payerID)
if err != nil {
c.Writer.Write([]byte(fmt.Sprintf("failed to get new client")))
return
}
_, err = client.GetAccessToken()
if err != nil {
c.Writer.Write([]byte(fmt.Sprint("failed to get new token ", err.Error())))
return
}
executeResult, er := client.ExecuteApprovedPayment(paymentID, payerID)
if er != nil {
c.Writer.Write([]byte(fmt.Sprint("failed to execute payment - ", er.Error(), " Result -->", executeResult)))
return
}
html := "<html><body><h1>Thank you! Paymen accepted!</h1></body></html>"
c.Writer.Write([]byte(fmt.Sprint(html, uID, executeResult)))
return
}
result after trying to approve payment
failed to execute payment - POST https://api.sandbox.paypal.com/v1/payments/payment//execute: 500 Result -->&{ [] []}
from paypal.
As I can see from this log and error, paymentID
is empty, because URL is missing it - POST https://api.sandbox.paypal.com/v1/payments/payment//execute
from paypal.
Related Issues (20)
- Get Order - Incomplete response object HOT 5
- Bug in ReauthorizeAuthorization HOT 1
- Make the mutex private in the structure HOT 2
- Suggestion: Error checking for malformed httpReq.Body on VerifyWebhookSignature HOT 1
- add landing page to v2/checkout/orders HOT 1
- Missed typing !
- POST https://api.sandbox.paypal.com/v2/checkout/orders: 401 Authentication failed due to invalid authentication credentials or a missing Authorization header. HOT 6
- How can i verify payment? HOT 3
- Removing deprecations HOT 1
- CHECKOUT.ORDER.COMPLETED response does not satisfty AnyEvent type HOT 2
- SendWithAuth requires GetAccessToken call explicitly HOT 2
- No dispute?
- Create Order error: paypal.Item.Tax is a String, API expects Object HOT 3
- Subscriber struct contains outdated fields HOT 1
- Create order body schema now uses payment_source HOT 4
- Paypal HOT 1
- Add Functionality to Create Estimates HOT 1
- Subscriber struct error HOT 3
- Specific Payment Method HOT 1
- AuthorizeOrderResponse uses invalid []PurchaseUnitRequest as PurchaseUnits. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from paypal.