github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/pilvytis/order_issuer.go (about)

     1  /*
     2   * Copyright (C) 2021 The "MysteriumNetwork/node" Authors.
     3   *
     4   * This program is free software: you can redistribute it and/or modify
     5   * it under the terms of the GNU General Public License as published by
     6   * the Free Software Foundation, either version 3 of the License, or
     7   * (at your option) any later version.
     8   *
     9   * This program is distributed in the hope that it will be useful,
    10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12   * GNU General Public License for more details.
    13   *
    14   * You should have received a copy of the GNU General Public License
    15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16   */
    17  
    18  package pilvytis
    19  
    20  // OrderIssuer combines the pilvytis API and order tracker.
    21  // Only the order issuer can issue new payment orders.
    22  type OrderIssuer struct {
    23  	api     *API
    24  	tracker *StatusTracker
    25  }
    26  
    27  // NewOrderIssuer returns a new order issuer.
    28  func NewOrderIssuer(api *API, tracker *StatusTracker) *OrderIssuer {
    29  	return &OrderIssuer{
    30  		api:     api,
    31  		tracker: tracker,
    32  	}
    33  }
    34  
    35  // CreatePaymentGatewayOrder will create a new payment order and send a notification to start tracking it.
    36  func (o *OrderIssuer) CreatePaymentGatewayOrder(cgo GatewayOrderRequest) (*GatewayOrderResponse, error) {
    37  	resp, err := o.api.createPaymentGatewayOrder(cgo)
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  	o.tracker.UpdateOrdersFor(cgo.Identity)
    42  
    43  	return resp, err
    44  }