Skip to content

Commit

Permalink
Merge pull request #5173 from mysteriumnetwork/pilvytis-google-client…
Browse files Browse the repository at this point in the history
…-callback

Provide mobile endpoint for google client callback
  • Loading branch information
tadaskay authored Jun 7, 2022
2 parents 27c3e36 + 9fbb8f0 commit 14f70f7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mobile/mysterium/payment_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,23 @@ func (mb *MobileNode) ListPaymentGatewayOrders(req *ListOrdersRequest) ([]byte,

return json.Marshal(orders)
}

// GatewayClientCallbackReq is the payload for GatewayClientCallback.
type GatewayClientCallbackReq struct {
IdentityAddress string
Gateway string
GooglePurchaseToken string
GoogleProductID string
}

// GatewayClientCallback triggers payment callback for google from client side.
func (mb *MobileNode) GatewayClientCallback(req *GatewayClientCallbackReq) error {
payload := struct {
PurchaseToken string `json:"purchase_token"`
GoogleProductID string `json:"google_product_id"`
}{
PurchaseToken: req.GooglePurchaseToken,
GoogleProductID: req.GoogleProductID,
}
return mb.pilvytis.GatewayClientCallback(identity.FromAddress(req.IdentityAddress), req.Gateway, payload)
}
11 changes: 11 additions & 0 deletions pilvytis/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,17 @@ func (a *API) GetPaymentGatewayOrderInvoice(id identity.Identity, oid string) ([
return ioutil.ReadAll(res.Body)
}

// GatewayClientCallback triggers a payment callback from the client-side.
// We will query the payment provider to verify the payment.
func (a *API) GatewayClientCallback(id identity.Identity, gateway string, payload any) error {
req, err := requests.NewSignedPostRequest(a.url, fmt.Sprintf("api/v2/payment/%s/client-callback", gateway), payload, a.signer(id))
if err != nil {
return err
}
var resp struct{}
return a.sendRequestAndParseResp(req, &resp)
}

type paymentOrderRequest struct {
ChannelAddress string `json:"channel_address"`
MystAmount string `json:"myst_amount"`
Expand Down
1 change: 1 addition & 0 deletions tequilapi/endpoints/pilvytis.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type api interface {
GetPaymentGatewayOrders(id identity.Identity) ([]pilvytis.GatewayOrderResponse, error)
GetPaymentGateways(optionsCurrency exchange.Currency) ([]pilvytis.GatewaysResponse, error)
GetRegistrationPaymentStatus(id identity.Identity) (*pilvytis.RegistrationPaymentResponse, error)
GatewayClientCallback(id identity.Identity, gateway string, payload any) error
}

type paymentsIssuer interface {
Expand Down
4 changes: 4 additions & 0 deletions tequilapi/endpoints/pilvytis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ func (mock *mockPilvytis) GetRegistrationPaymentStatus(id identity.Identity) (*p
}, nil
}

func (mock *mockPilvytis) GatewayClientCallback(id identity.Identity, gateway string, payload any) error {
return nil
}

type mockPilvytisLocation struct{}

func (mock *mockPilvytisLocation) GetOrigin() locationstate.Location {
Expand Down

0 comments on commit 14f70f7

Please sign in to comment.