forked from go-packages/paypal
billing structures
This commit is contained in:
parent
6745ee0f80
commit
cd4c6831c7
3
billing.go
Normal file
3
billing.go
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
package paypalsdk
|
||||||
|
|
||||||
|
import ()
|
164
billing_test.go
Normal file
164
billing_test.go
Normal file
|
@ -0,0 +1,164 @@
|
||||||
|
package paypalsdk
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestJsonStructure(t *testing.T) {
|
||||||
|
expected_str := `{
|
||||||
|
"name": "Plan with Regular and Trial Payment Definitions",
|
||||||
|
"description": "Plan with regular and trial payment definitions.",
|
||||||
|
"type": "fixed",
|
||||||
|
"payment_definitions": [
|
||||||
|
{
|
||||||
|
"name": "Regular payment definition",
|
||||||
|
"type": "REGULAR",
|
||||||
|
"frequency": "MONTH",
|
||||||
|
"frequency_interval": "2",
|
||||||
|
"amount":
|
||||||
|
{
|
||||||
|
"value": "100",
|
||||||
|
"currency": "USD"
|
||||||
|
},
|
||||||
|
"cycles": "12",
|
||||||
|
"charge_models": [
|
||||||
|
{
|
||||||
|
"type": "SHIPPING",
|
||||||
|
"amount":
|
||||||
|
{
|
||||||
|
"value": "10",
|
||||||
|
"currency": "USD"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TAX",
|
||||||
|
"amount":
|
||||||
|
{
|
||||||
|
"value": "12",
|
||||||
|
"currency": "USD"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Trial payment definition",
|
||||||
|
"type": "trial",
|
||||||
|
"frequency": "week",
|
||||||
|
"frequency_interval": "5",
|
||||||
|
"amount":
|
||||||
|
{
|
||||||
|
"value": "9.19",
|
||||||
|
"currency": "USD"
|
||||||
|
},
|
||||||
|
"cycles": "2",
|
||||||
|
"charge_models": [
|
||||||
|
{
|
||||||
|
"type": "SHIPPING",
|
||||||
|
"amount":
|
||||||
|
{
|
||||||
|
"value": "1",
|
||||||
|
"currency": "USD"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TAX",
|
||||||
|
"amount":
|
||||||
|
{
|
||||||
|
"value": "2",
|
||||||
|
"currency": "USD"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}],
|
||||||
|
"merchant_preferences":
|
||||||
|
{
|
||||||
|
"setup_fee":
|
||||||
|
{
|
||||||
|
"value": "1",
|
||||||
|
"currency": "USD"
|
||||||
|
},
|
||||||
|
"return_url": "http://www.paypal.com",
|
||||||
|
"cancel_url": "http://www.paypal.com/cancel",
|
||||||
|
"auto_bill_amount": "YES",
|
||||||
|
"initial_fail_amount_action": "CONTINUE",
|
||||||
|
"max_fail_attempts": "0"
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
plan := BillingPlan{
|
||||||
|
Name: "Plan with Regular and Trial Payment Definitions",
|
||||||
|
Description: "Plan with regular and trial payment definitions.",
|
||||||
|
Type: "fixed",
|
||||||
|
PaymentDefinitions: []PaymentDefinition{
|
||||||
|
PaymentDefinition{
|
||||||
|
Name: "Regular payment definition",
|
||||||
|
Type: "REGULAR",
|
||||||
|
Frequency: "MONTH",
|
||||||
|
FrequencyInterval: "2",
|
||||||
|
Amount: AmountPayout{
|
||||||
|
Value: "100",
|
||||||
|
Currency: "USD",
|
||||||
|
},
|
||||||
|
Cycles: "12",
|
||||||
|
ChargeModels: []ChargeModel{
|
||||||
|
ChargeModel{
|
||||||
|
Type: "SHIPPING",
|
||||||
|
Amount: AmountPayout{
|
||||||
|
Value: "10",
|
||||||
|
Currency: "USD",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ChargeModel{
|
||||||
|
Type: "TAX",
|
||||||
|
Amount: AmountPayout{
|
||||||
|
Value: "12",
|
||||||
|
Currency: "USD",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
PaymentDefinition{
|
||||||
|
Name: "Trial payment definition",
|
||||||
|
Type: "trial",
|
||||||
|
Frequency: "week",
|
||||||
|
FrequencyInterval: "5",
|
||||||
|
Amount: AmountPayout{
|
||||||
|
Value: "9.19",
|
||||||
|
Currency: "USD",
|
||||||
|
},
|
||||||
|
Cycles: "2",
|
||||||
|
ChargeModels: []ChargeModel{
|
||||||
|
ChargeModel{
|
||||||
|
Type: "SHIPPING",
|
||||||
|
Amount: AmountPayout{
|
||||||
|
Value: "1",
|
||||||
|
Currency: "USD",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ChargeModel{
|
||||||
|
Type: "TAX",
|
||||||
|
Amount: AmountPayout{
|
||||||
|
Value: "2",
|
||||||
|
Currency: "USD",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
MerchantPreferences: MerchantPreferences{
|
||||||
|
SetupFee: AmountPayout{
|
||||||
|
Value: "1",
|
||||||
|
Currency: "USD",
|
||||||
|
},
|
||||||
|
ReturnUrl: "http://www.paypal.com",
|
||||||
|
CancelUrl: "http://www.paypal.com/cancel",
|
||||||
|
AutoBillAmount: "YES",
|
||||||
|
InitialFailAmountAction: "CONTINUE",
|
||||||
|
MaxFailAttempts: "0",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_, err := json.Marshal(&plan)
|
||||||
|
expected := new(BillingPlan)
|
||||||
|
json.Unmarshal([]byte(expected_str), expected)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, expected, &plan, "Wrong billing builder")
|
||||||
|
}
|
36
types.go
36
types.go
|
@ -93,6 +93,15 @@ type (
|
||||||
SenderBatchHeader *SenderBatchHeader `json:"sender_batch_header,omitempty"`
|
SenderBatchHeader *SenderBatchHeader `json:"sender_batch_header,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BillingPlan struct
|
||||||
|
BillingPlan struct {
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
Description string `json:"description,omitempty"`
|
||||||
|
Type string `json:"type,omitempty"`
|
||||||
|
PaymentDefinitions []PaymentDefinition `json:"payment_definitions,omitempty"`
|
||||||
|
MerchantPreferences MerchantPreferences `json:"merchant_preferences,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Capture struct
|
// Capture struct
|
||||||
Capture struct {
|
Capture struct {
|
||||||
Amount *Amount `json:"amount,omitempty"`
|
Amount *Amount `json:"amount,omitempty"`
|
||||||
|
@ -105,6 +114,12 @@ type (
|
||||||
Links []Link `json:"links,omitempty"`
|
Links []Link `json:"links,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ChargeModel struct
|
||||||
|
ChargeModel struct {
|
||||||
|
Type string `json:"type,omitempty"`
|
||||||
|
Amount AmountPayout `json:"amount,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Client represents a Paypal REST API Client
|
// Client represents a Paypal REST API Client
|
||||||
Client struct {
|
Client struct {
|
||||||
Client *http.Client
|
Client *http.Client
|
||||||
|
@ -218,6 +233,16 @@ type (
|
||||||
Enctype string `json:"enctype,omitempty"`
|
Enctype string `json:"enctype,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MerchantPreferences struct
|
||||||
|
MerchantPreferences struct {
|
||||||
|
SetupFee AmountPayout `json:"setup_fee,omitempty"`
|
||||||
|
ReturnUrl string `json:"return_url,omitempty"`
|
||||||
|
CancelUrl string `json:"cancel_url,omitempty"`
|
||||||
|
AutoBillAmount string `json:"auto_bill_amount,omitempty"`
|
||||||
|
InitialFailAmountAction string `json:"initial_fail_amount_action,omitempty"`
|
||||||
|
MaxFailAttempts string `json:"max_fail_attempts,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Order struct
|
// Order struct
|
||||||
Order struct {
|
Order struct {
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
|
@ -263,6 +288,17 @@ type (
|
||||||
ExperienceProfileID string `json:"experience_profile_id,omitempty"`
|
ExperienceProfileID string `json:"experience_profile_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PaymentDefinition struct
|
||||||
|
PaymentDefinition struct {
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
Type string `json:"type,omitempty"`
|
||||||
|
Frequency string `json:"frequency,omitempty"`
|
||||||
|
FrequencyInterval string `json:"frequency_interval,omitempty"`
|
||||||
|
Amount AmountPayout `json:"amount,omitempty"`
|
||||||
|
Cycles string `json:"cycles,omitempty"`
|
||||||
|
ChargeModels []ChargeModel `json:"charge_models,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// PaymentResponse structure
|
// PaymentResponse structure
|
||||||
PaymentResponse struct {
|
PaymentResponse struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user