Skip to content

Commit aa78339

Browse files
committed
More methods
1 parent b4471bf commit aa78339

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

src/Api/Transactions.php

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,59 @@ public function setSignHeader( $sign ) {
4141
}
4242

4343
/**
44+
* @param $data
45+
*
4446
* @return EcommerceResponse
4547
* @throws ApiException
4648
*/
47-
public function createTransaction( $data ) {
49+
public function createTransaction( $data ): EcommerceResponse {
50+
$body = $this->getEcommerceIncomingRequest( $data );
51+
$this->setAuthorizationHeader();
52+
$sign = $this->generateSignature( $this->getEcommerceIncomingRequestData( $body ) );
53+
$this->setSignHeader( $sign );
54+
55+
return $this->getClient()->setEcommerceRequest( $body, );
56+
}
57+
58+
/**
59+
* @param $data
60+
*
61+
* @return EcommerceIncomingRequest
62+
*/
63+
public function getEcommerceIncomingRequest( $data ): EcommerceIncomingRequest {
4864
$data['merchantId'] = $data['merchantId'] ?? $this->getCredentials()->getEmail();
4965

50-
$body = new EcommerceIncomingRequest();
66+
$body = new EcommerceIncomingRequest();
5167

5268
foreach ( $data as $key => $value ) {
5369
$setter = sprintf( 'set%s', ucfirst( $key ) );
5470
if ( method_exists( $body, $setter ) ) {
5571
$body->$setter( $value );
5672
}
5773
}
58-
$this->setAuthorizationHeader();
59-
$data = Utils::streamFor( $body )->getContents();
60-
$sign = $this->generateSignature( $data );
61-
$this->setSignHeader( $sign );
6274

63-
return $this->getClient()->setEcommerceRequest( $body, );
75+
return $body;
76+
}
77+
78+
/**
79+
* Pass args to this method to get the sign with added args
80+
* @param array $data
81+
*
82+
* @return false|string
83+
*/
84+
public function getSignForRequest( array $data ) {
85+
$body = $this->getEcommerceIncomingRequest( $data );
86+
87+
return $this->generateSignature( $this->getEcommerceIncomingRequestData( $body ) );
88+
}
89+
90+
/**
91+
* @param EcommerceIncomingRequest $request
92+
*
93+
* @return string
94+
*/
95+
public function getEcommerceIncomingRequestData( EcommerceIncomingRequest $request ): string {
96+
return Utils::streamFor( $request )->getContents();
6497
}
6598

6699
/**

0 commit comments

Comments
 (0)