mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 10:21:03 +01:00
#7 CreateSinglePayout
This commit is contained in:
parent
52f3012ca1
commit
ebc7c22c7c
25
README.md
25
README.md
|
@ -22,6 +22,7 @@
|
|||
* POST /v1/payments/orders/**ID**/do-void
|
||||
* POST /v1/identity/openidconnect/tokenservice
|
||||
* GET /v1/identity/openidconnect/userinfo/?schema=**SCHEMA**
|
||||
* POST /v1/payments/payouts?sync_mode=true
|
||||
|
||||
#### Missing endpoints
|
||||
It is possible that some endpoints are missing in this SDK Client, but you can use built-in **paypalsdk** functions to perform a request: **NewClient -> NewRequest -> SendWithAuth**
|
||||
|
@ -207,6 +208,30 @@ token, err := c.GrantNewAccessTokenFromRefreshToken("<Refresh-Token>")
|
|||
userInfo, err := c.GetUserInfo("openid")
|
||||
```
|
||||
|
||||
#### Create single payout to email
|
||||
|
||||
```go
|
||||
payout := paypalsdk.Payout{
|
||||
SenderBatchHeader: &paypalsdk.SenderBatchHeader{
|
||||
EmailSubject: "Subject will be displayed on PayPal",
|
||||
},
|
||||
Items: []paypalsdk.PayoutItem{
|
||||
paypalsdk.PayoutItem{
|
||||
RecipientType: "EMAIL",
|
||||
Receiver: "single-email-payout@mail.com",
|
||||
Amount: &paypalsdk.AmountPayout{
|
||||
Value: "15.11",
|
||||
Currency: "USD",
|
||||
},
|
||||
Note: "Optional note",
|
||||
SenderItemID: "Optional Item ID",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
payoutResp, err := c.CreateSinglePayout(payout)
|
||||
```
|
||||
|
||||
#### How to Contribute
|
||||
|
||||
* Fork a repository
|
||||
|
|
|
@ -144,4 +144,29 @@ func main() {
|
|||
} else {
|
||||
fmt.Println("ERROR: " + err.Error())
|
||||
}
|
||||
|
||||
payout := paypalsdk.Payout{
|
||||
SenderBatchHeader: &paypalsdk.SenderBatchHeader{
|
||||
EmailSubject: "Subject will be displayed on PayPal",
|
||||
},
|
||||
Items: []paypalsdk.PayoutItem{
|
||||
paypalsdk.PayoutItem{
|
||||
RecipientType: "EMAIL",
|
||||
Receiver: "single-email-payout@mail.com",
|
||||
Amount: &paypalsdk.AmountPayout{
|
||||
Value: "15.11",
|
||||
Currency: "USD",
|
||||
},
|
||||
Note: "Optional note",
|
||||
SenderItemID: "Optional Item ID",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
payoutResp, err := c.CreateSinglePayout(payout)
|
||||
if err == nil && len(payoutResp.Items) > 0 {
|
||||
fmt.Println("DEBUG: PayoutItemID=" + payoutResp.Items[0].PayoutItemID)
|
||||
} else {
|
||||
fmt.Println("ERROR: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
|
22
payout.go
Normal file
22
payout.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package paypalsdk
|
||||
|
||||
import "fmt"
|
||||
|
||||
// CreateSinglePayout submits a payout with a synchronous API call, which immediately returns the results of a PayPal payment.
|
||||
// For email payout set RecipientType: "EMAIL" and receiver email into Receiver
|
||||
// Endpoint: POST /v1/payments/payouts?sync_mode=true
|
||||
func (c *Client) CreateSinglePayout(p Payout) (*PayoutResponse, error) {
|
||||
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payouts?sync_mode=true"), p)
|
||||
if err != nil {
|
||||
return &PayoutResponse{}, err
|
||||
}
|
||||
|
||||
response := &PayoutResponse{}
|
||||
|
||||
err = c.SendWithAuth(req, response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
32
payout_test.go
Normal file
32
payout_test.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package paypalsdk
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCreateSinglePayout(t *testing.T) {
|
||||
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
|
||||
c.GetAccessToken()
|
||||
|
||||
payout := Payout{
|
||||
SenderBatchHeader: &SenderBatchHeader{
|
||||
EmailSubject: "Subject will be displayed on PayPal",
|
||||
},
|
||||
Items: []PayoutItem{
|
||||
PayoutItem{
|
||||
RecipientType: "EMAIL",
|
||||
Receiver: "single-email-payout@mail.com",
|
||||
Amount: &AmountPayout{
|
||||
Value: "15.11",
|
||||
Currency: "USD",
|
||||
},
|
||||
Note: "Optional note",
|
||||
SenderItemID: "Optional Item ID",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
p, err := c.CreateSinglePayout(payout)
|
||||
|
||||
if err != nil || len(p.Items) != 1 {
|
||||
t.Errorf("Test single payout is not created")
|
||||
}
|
||||
}
|
62
types.go
62
types.go
|
@ -32,6 +32,12 @@ type (
|
|||
Total string `json:"total"`
|
||||
}
|
||||
|
||||
// AmountPayout https://developer.paypal.com/docs/integration/direct/create-single-payout/
|
||||
AmountPayout struct {
|
||||
Currency string `json:"currency"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// Authorization rhttps://developer.paypal.com/webapps/developer/docs/api/#authorization-object
|
||||
Authorization struct {
|
||||
Amount *Amount `json:"amount,omitempty"`
|
||||
|
@ -47,6 +53,17 @@ type (
|
|||
ProtectionEligibilityType string `json:"protection_eligibility_type,omitempty"`
|
||||
}
|
||||
|
||||
// BatchHeader https://developer.paypal.com/docs/integration/direct/create-single-payout/
|
||||
BatchHeader struct {
|
||||
Amount *AmountPayout `json:"amount,omitempty"`
|
||||
Fees *AmountPayout `json:"fees,omitempty"`
|
||||
PayoutBatchID string `json:"payout_batch_id,omitempty"`
|
||||
BatchStatus string `json:"batch_status,omitempty"`
|
||||
TimeCreated *time.Time `json:"time_created,omitempty"`
|
||||
TimeCompleted *time.Time `json:"time_completed,omitempty"`
|
||||
SenderBatchHeader *SenderBatchHeader `json:"sender_batch_header,omitempty"`
|
||||
}
|
||||
|
||||
// Capture https://developer.paypal.com/webapps/developer/docs/api/#capture-object
|
||||
Capture struct {
|
||||
Amount *Amount `json:"amount,omitempty"`
|
||||
|
@ -149,9 +166,9 @@ type (
|
|||
// Links https://developer.paypal.com/webapps/developer/docs/api/#itemlist-object
|
||||
Links struct {
|
||||
Href string `json:"href"`
|
||||
Rel string `json:"rel"`
|
||||
Method string `json:"method"`
|
||||
Enctype string `json:"enctype"`
|
||||
Rel string `json:"rel,omitempty"`
|
||||
Method string `json:"method,omitempty"`
|
||||
Enctype string `json:"enctype,omitempty"`
|
||||
}
|
||||
|
||||
// Order https://developer.paypal.com/webapps/developer/docs/api/#order-object
|
||||
|
@ -211,6 +228,40 @@ type (
|
|||
Links []PaymentLink `json:"links"`
|
||||
}
|
||||
|
||||
// Payout https://developer.paypal.com/docs/integration/direct/create-single-payout/
|
||||
Payout struct {
|
||||
SenderBatchHeader *SenderBatchHeader `json:"sender_batch_header"`
|
||||
Items []PayoutItem `json:"items"`
|
||||
}
|
||||
|
||||
// PayoutItem https://developer.paypal.com/docs/integration/direct/create-single-payout/
|
||||
PayoutItem struct {
|
||||
RecipientType string `json:"recipient_type"`
|
||||
Receiver string `json:"receiver"`
|
||||
Amount *AmountPayout `json:"amount"`
|
||||
Note string `json:"note,omitempty"`
|
||||
SenderItemID string `json:"sender_item_id,omitempty"`
|
||||
}
|
||||
|
||||
// PayoutItemResponse https://developer.paypal.com/docs/integration/direct/create-single-payout/
|
||||
PayoutItemResponse struct {
|
||||
PayoutItemID string `json:"payout_item_id"`
|
||||
TransactionID string `json:"transaction_id"`
|
||||
TransactionStatus string `json:"transaction_status"`
|
||||
PayoutBatchID string `json:"payout_batch_id,omitempty"`
|
||||
PayoutItemFee *AmountPayout `json:"payout_item_fee,omitempty"`
|
||||
PayoutItem *PayoutItem `json:"payout_item"`
|
||||
TimeProcessed *time.Time `json:"time_processed,omitempty"`
|
||||
Links []Links `json:"links"`
|
||||
}
|
||||
|
||||
// PayoutResponse https://developer.paypal.com/docs/integration/direct/create-single-payout/
|
||||
PayoutResponse struct {
|
||||
BatchHeader *BatchHeader `json:"batch_header"`
|
||||
Items []PayoutItemResponse `json:"items"`
|
||||
Links []Links `json:"links"`
|
||||
}
|
||||
|
||||
// RedirectURLs https://developer.paypal.com/webapps/developer/docs/api/#redirecturls-object
|
||||
RedirectURLs struct {
|
||||
ReturnURL string `json:"return_url,omitempty"`
|
||||
|
@ -246,6 +297,11 @@ type (
|
|||
Links []Links `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
// SenderBatchHeader https://developer.paypal.com/docs/integration/direct/create-single-payout/
|
||||
SenderBatchHeader struct {
|
||||
EmailSubject string `json:"email_subject"`
|
||||
}
|
||||
|
||||
// ShippingAddress https://developer.paypal.com/webapps/developer/docs/api/#shippingaddredd-object
|
||||
ShippingAddress struct {
|
||||
RecipientName string `json:"recipient_name,omitempty"`
|
||||
|
|
Loading…
Reference in New Issue
Block a user