Skip to content

Commit

Permalink
Merge pull request #106 from shauny-xendit/DIGI-7112/update-ewallet-c…
Browse files Browse the repository at this point in the history
…harge-request

feat: [DIGI-7112] update ewallet charge request
  • Loading branch information
sekaranglila authored Nov 25, 2022
2 parents 303edbc + 6e3917e commit 2ecfab2
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 140 deletions.
96 changes: 73 additions & 23 deletions ewallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package xendit

import "time"

// EWalletTypeEnum constants are the available e-wallet type
//IMPORTANT: EWALLET PAYMENT WILL BE DEPRECATED. PLEASE USE EWALLET CHARGE.

// EWalletTypeEnum constants are the available e-wallet type for Ewallet Payment
type EWalletTypeEnum string

// This consists the values that EWalletTypeEnum can take
Expand Down Expand Up @@ -45,27 +47,75 @@ type EWalletBasketItem struct {
Metadata map[string]interface{} `json:"metadata,omitempty"`
}

// ChargeOutputStatus represents the enum for charge output status for an Ewallet Charge
type ChargeOutputStatus string

// These are the available ChargeOutputStatus values for an Ewallet Charge
const (
ChargeOutputStatusPending ChargeOutputStatus = "PENDING"
ChargeOutputStatusFailed ChargeOutputStatus = "FAILED"
ChargeOutputStatusSucceeded ChargeOutputStatus = "SUCCEEDED"
ChargeOutputStatusVoided ChargeOutputStatus = "VOIDED"
ChargeOutputStatusRefunded ChargeOutputStatus = "REFUNDED"
)

// Actions represents the actions of an Ewallet Charge.
type Actions struct {
DesktopWebCheckoutURL *string `json:"desktop_web_checkout_url"`
MobileWebCheckoutURL *string `json:"mobile_web_checkout_url"`
MobileDeeplinkCheckoutURL *string `json:"mobile_deeplink_checkout_url"`
QrCheckoutString *string `json:"qr_checkout_string"`
}

// ShippingInformation struct for Ewallet Charge ShippingInformation
type ShippingInformation struct {
Country string `json:"country"` //two letter country code eg. ID/PH
StreetLine1 string `json:"street_line1"`
StreetLine2 *string `json:"street_line2,omitempty"`
City string `json:"city"`
ProvinceState string `json:"province_state"`
PostalCode string `json:"postal_code"`
}

//
type EwalletCustomer struct {
ReferenceId *string `json:"reference_id,omitempty"`
GivenNames *string `json:"given_names,omitempty"`
Surname *string `json:"surname,omitempty"`
Email *string `json:"email,omitempty"`
MobileNumber *string `json:"mobile_number,omitempty"`
DomicileOfRegistration *string `json:"domicile_of_registration,omitempty"`
DateOfRegistration *string `json:"date_of_registration,omitempty"`
}

//EWalletCharge represents the response from Xendit Ewallet Charge API
type EWalletCharge struct {
ID string `json:"id"`
BusinessID string `json:"business_id"`
ReferenceID string `json:"reference_id"`
Status string `json:"status"`
Currency string `json:"currency"`
ChargeAmount float64 `json:"charge_amount"`
CaptureAmount float64 `json:"capture_amount"`
CheckoutMethod string `json:"checkout_method"`
ChannelCode string `json:"channel_code"`
ChannelProperties map[string]string `json:"channel_properties"`
Actions map[string]string `json:"actions"`
IsRedirectRequired bool `json:"is_redirect_required"`
CallbackURL string `json:"callback_url"`
Created string `json:"created"`
Updated string `json:"updated"`
VoidedAt string `json:"voided_at,omitempty"`
CaptureNow bool `json:"capture_now"`
CustomerID string `json:"customer_id,omitempty"`
PaymentMethodID string `json:"payment_method_id,omitempty"`
FailureCode string `json:"failure_code,omitempty"`
Basket []EWalletBasketItem `json:"basket,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
ID string `json:"id"`
BusinessID string `json:"business_id"`
ReferenceID string `json:"reference_id"`
Status ChargeOutputStatus `json:"status"`
Currency string `json:"currency"`
ChargeAmount float64 `json:"charge_amount"`
CaptureAmount float64 `json:"capture_amount"`
PayerChargedCurrency string `json:"payer_charged_currency,omitempty"`
PayerChargedAmount float64 `json:"payer_charged_amount,omitempty"`
RefundedAmount float64 `json:"refunded_amount,omitempty"`
CheckoutMethod string `json:"checkout_method"`
ChannelCode string `json:"channel_code"`
ChannelProperties map[string]string `json:"channel_properties"`
Actions Actions `json:"actions"`
IsRedirectRequired bool `json:"is_redirect_required"`
CallbackURL string `json:"callback_url"`
Created string `json:"created"`
Updated string `json:"updated"`
VoidStatus string `json:"void_status,omitempty"`
VoidedAt string `json:"voided_at,omitempty"`
CaptureNow bool `json:"capture_now"`
CustomerID string `json:"customer_id,omitempty"`
Customer *EwalletCustomer `json:"customer,omitempty"`
PaymentMethodID string `json:"payment_method_id,omitempty"`
FailureCode string `json:"failure_code,omitempty"`
Basket []EWalletBasketItem `json:"basket,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
ShippingInformation *ShippingInformation `json:"shipping_information,omitempty"`
}
58 changes: 2 additions & 56 deletions ewallet/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,6 @@ type getPaymentStatusResponse struct {
BusinessID string `json:"business_id,omitempty"`
}

type EWalletChargeResponse struct {
ID string `json:"id"`
BusinessID string `json:"business_id"`
ReferenceID string `json:"reference_id"`
Status string `json:"status"`
Currency string `json:"currency"`
ChargeAmount float64 `json:"charge_amount"`
CaptureAmount float64 `json:"capture_amount"`
CheckoutMethod string `json:"checkout_method"`
ChannelCode string `json:"channel_code"`
ChannelProperties map[string]string `json:"channel_properties"`
Actions map[string]string `json:"actions"`
IsRedirectRequired bool `json:"is_redirect_required"`
CallbackURL string `json:"callback_url"`
Created string `json:"created"`
Updated string `json:"updated"`
VoidedAt string `json:"voided_at"`
CaptureNow bool `json:"capture_now"`
CustomerID string `json:"customer_id"`
PaymentMethodID string `json:"payment_method_id"`
FailureCode string `json:"failure_code"`
Basket []xendit.EWalletBasketItem `json:"basket"`
Metadata map[string]interface{} `json:"metadata"`
}

func (r *getPaymentStatusResponse) toEwalletResponse() *xendit.EWallet {
return &xendit.EWallet{
EWalletType: r.EWalletType,
Expand All @@ -64,33 +39,6 @@ func (r *getPaymentStatusResponse) toEwalletResponse() *xendit.EWallet {
}
}

func (r *EWalletChargeResponse) toEWalletChargeResponse() *xendit.EWalletCharge {
return &xendit.EWalletCharge{
ID: r.ID,
BusinessID: r.BusinessID,
ReferenceID: r.ReferenceID,
Status: r.Status,
Currency: r.Currency,
ChargeAmount: r.ChargeAmount,
CaptureAmount: r.CaptureAmount,
CheckoutMethod: r.CheckoutMethod,
ChannelCode: r.ChannelCode,
ChannelProperties: r.ChannelProperties,
Actions: r.Actions,
IsRedirectRequired: r.IsRedirectRequired,
CallbackURL: r.CallbackURL,
Created: r.Created,
Updated: r.Updated,
VoidedAt: r.VoidedAt,
CaptureNow: r.CaptureNow,
CustomerID: r.CustomerID,
PaymentMethodID: r.PaymentMethodID,
FailureCode: r.FailureCode,
Basket: r.Basket,
Metadata: r.Metadata,
}
}

// CreatePayment creates new payment
func (c *Client) CreatePayment(data *CreatePaymentParams) (*xendit.EWallet, *xendit.Error) {
return c.CreatePaymentWithContext(context.Background(), data)
Expand Down Expand Up @@ -212,7 +160,7 @@ func (c *Client) GetEWalletChargeStatusWithContext(ctx context.Context, data *Ge
return nil, validator.APIValidatorErr(err)
}

tempResponse := &EWalletChargeResponse{}
response := &xendit.EWalletCharge{}
header := http.Header{}

if data.ForUserID != "" {
Expand All @@ -226,13 +174,11 @@ func (c *Client) GetEWalletChargeStatusWithContext(ctx context.Context, data *Ge
c.Opt.SecretKey,
header,
nil,
tempResponse,
response,
)
if err != nil {
return nil, err
}

response := tempResponse.toEWalletChargeResponse()

return response, nil
}
Loading

0 comments on commit 2ecfab2

Please sign in to comment.