blue-factory / transbank-sdk-golang

Unofficial Transbank Golang SDK
GNU General Public License v3.0
26 stars 6 forks source link

Separation of concerns - Signature of payload and Webpay transaction types #4

Closed rvillablanca closed 4 years ago

rvillablanca commented 4 years ago

This is a proposal PR that separates in two packages the responsabilities of each one. A new package github.com/microapis/transbank-sdk-golang/pkg/webpay/sign was created which is responsible of the signature of any Webpay transaction (normal, mall, oneclick, etc).

The idea is to embed the type sign.SOAPSigner in the required transaction:

type Webpay struct {
    sign.SOAPSigner
    config *configuration
}

...

func new(c *configuration) *Webpay {
    w := &Webpay{
        config:     c,
        SOAPSigner: sign.New(c.PublicCert, c.PrivateCert),
    }

    return w
}

...

func (w *Webpay) SOAP(payload interface{}) ([]byte, error) {
    XMLReq, err := w.Sign(payload)
    if err != nil {
        return nil, err
    }

...

}

This way the signature and the payload are separade and less coupled.

Additionally this PR includes some small fixes include in #3

cagodoy commented 4 years ago

@rvillablanca Thanks for your work. 🚀

It is a good idea to separate the logic between webpay and signer, it's more reusable.

But what do you think if we move the signature package to /pkg? (microapis/transbank-sdk-golang/pkg/sign)

Just tell me what you think.

rvillablanca commented 4 years ago

I think it should be ok, the important part is to separete them. I think a more clear separation would be even something like a microapis/transbank-sdk-golang/pkg/soap for parts that are related with the SOAP message only, because right now with this refactor some types like SoapFault now will live under sign package. I notice that after doing this PR, but it could be improved in another PR.

rvillablanca commented 4 years ago

Great work BTW :+1:

cagodoy commented 4 years ago

Sounds good. Let's merge this PR and i send another with the proposal. (#5)

Thanks again.