You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.4 KiB
127 lines
3.4 KiB
package paypal
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/plutov/paypal/v4"
|
|
"testing"
|
|
)
|
|
|
|
func TestAccessToken(t *testing.T) {
|
|
client := NewClient()
|
|
err, token := client.AccessToken()
|
|
if err != nil {
|
|
return
|
|
}
|
|
fmt.Println(token.AccessToken)
|
|
}
|
|
|
|
var at = "A21AALPXmF_rZTWsNxqAANC-NJuHG7oL9DalUJpm9j4AyWG60_Th5z7mAYDjn8r_0s_Z0Vhy6YOFKBr_36M0fzm5GTjW9Sx-Q"
|
|
var orderId = "05532809YA540721Y"
|
|
|
|
func TestCreateOrder(t *testing.T) {
|
|
var (
|
|
err error
|
|
token *AccessToken
|
|
params CreateOrderRequest
|
|
result OrderDetail
|
|
)
|
|
client := NewClient()
|
|
err, token = client.AccessToken()
|
|
if err != nil {
|
|
return
|
|
}
|
|
params.PurchaseUnits = []PurchaseUnit{{
|
|
Amount: PurchaseAmount{
|
|
Amount: Amount{
|
|
CurrencyCode: "USD",
|
|
Value: "1.01",
|
|
},
|
|
},
|
|
}}
|
|
//params.PaymentSource.Paypal.Address.CountryCode = "C2"
|
|
//params.PaymentSource.Paypal.Phone.PhoneNumber.NationalNumber = "2159672152"
|
|
//params.PaymentSource.Paypal.Attributes.Customer.ID = "RE695WNBR7XJQ"
|
|
//params.PaymentSource.Paypal.ExperienceContext.ReturnURL = "https://seller-dev.bkbackground.com/funds_manage/list"
|
|
//params.PaymentSource.Paypal.ExperienceContext.CancelURL = "https://seller-dev.bkbackground.com/goods_manage/list"
|
|
params.ApplicationContext.ReturnURL = "https://seller-dev.bkbackground.com/funds_manage/list"
|
|
params.ApplicationContext.CancelURL = "https://seller-dev.bkbackground.com/goods_manage/list"
|
|
err, result = CreateOrder(token.AccessToken, ¶ms)
|
|
if err != nil {
|
|
return
|
|
}
|
|
fmt.Println(result.ID)
|
|
}
|
|
|
|
func TestCreateOrder2(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
c, _ := paypal.NewClient("AR_HpVdxFURck7pjWsej_8CKbUAaAcKeEp4G7z6LdU1Vd-L5D5x_3Z6_vMVjhcWA5eZ7pbT9bTCwCD1S", "EL1gdqvwDaDCfj62C86LT3ptFgIJYsIrNg_lPpuepASe4P3za_Np3iOk_rytfU7SbYgXnSU7Z6WxxJot", paypal.APIBaseSandBox)
|
|
_, _ = c.GetAccessToken(ctx)
|
|
|
|
orderResponse, err := c.CreateOrder(
|
|
ctx,
|
|
paypal.OrderIntentCapture,
|
|
[]paypal.PurchaseUnitRequest{
|
|
{
|
|
Amount: &paypal.PurchaseUnitAmount{
|
|
Value: "7.00",
|
|
Currency: "USD",
|
|
},
|
|
},
|
|
},
|
|
&paypal.CreateOrderPayer{},
|
|
&paypal.ApplicationContext{},
|
|
)
|
|
if err != nil {
|
|
t.Errorf("Not expected error for CreateOrder(), got %s", err.Error())
|
|
}
|
|
fmt.Println(orderResponse)
|
|
}
|
|
|
|
func TestGetOrder(t *testing.T) {
|
|
var (
|
|
err error
|
|
result OrderDetail
|
|
)
|
|
err, result = GetOrder(at, orderId)
|
|
if err != nil {
|
|
return
|
|
}
|
|
fmt.Println(result.ID)
|
|
}
|
|
|
|
func TestConfirmOrder(t *testing.T) {
|
|
var (
|
|
err error
|
|
params PaymentSourceRequest
|
|
result OrderDetail
|
|
)
|
|
//params.PaymentSource.Paypal.Address.CountryCode = "C2"
|
|
//params.PaymentSource.Paypal.Phone.PhoneNumber.NationalNumber = "2159672152"
|
|
//params.PaymentSource.Paypal.Attributes.Customer.ID = "RE695WNBR7XJQ"
|
|
//params.PaymentSource.Paypal.ExperienceContext.ReturnURL = ""
|
|
//params.PaymentSource.Paypal.ExperienceContext.CancelURL = ""
|
|
err, result = ConfirmOrder(at, orderId, ¶ms)
|
|
if err != nil {
|
|
return
|
|
}
|
|
fmt.Println(result.ID)
|
|
}
|
|
func TestCapturePaymentOrder(t *testing.T) {
|
|
var (
|
|
err error
|
|
params PaymentSourceRequest
|
|
result OrderDetail
|
|
)
|
|
//params.PaymentSource.Paypal.Address.CountryCode = "C2"
|
|
//params.PaymentSource.Paypal.Phone.PhoneNumber.NationalNumber = "2159672152"
|
|
//params.PaymentSource.Paypal.Attributes.Customer.ID = "RE695WNBR7XJQ"
|
|
//params.PaymentSource.Paypal.ExperienceContext.ReturnURL = ""
|
|
//params.PaymentSource.Paypal.ExperienceContext.CancelURL = ""
|
|
err, result = CapturePaymentOrder(at, orderId, ¶ms)
|
|
if err != nil {
|
|
return
|
|
}
|
|
fmt.Println(result.ID)
|
|
}
|
|
|