|
@@ 108-139 (lines=32) @@
|
| 105 |
|
* |
| 106 |
|
* @return void |
| 107 |
|
*/ |
| 108 |
|
public function set_api_version() { |
| 109 |
|
|
| 110 |
|
// Set Application Info. |
| 111 |
|
give_stripe_set_app_info(); |
| 112 |
|
|
| 113 |
|
try { |
| 114 |
|
|
| 115 |
|
// Set API Version to latest. |
| 116 |
|
\Stripe\Stripe::setApiVersion( $this->api_version ); |
| 117 |
|
|
| 118 |
|
} catch ( \Stripe\Error\Base $e ) { |
| 119 |
|
|
| 120 |
|
// Log Error. |
| 121 |
|
$this->log_error( $e ); |
| 122 |
|
|
| 123 |
|
} catch ( Exception $e ) { |
| 124 |
|
|
| 125 |
|
// Something went wrong outside of Stripe. |
| 126 |
|
give_record_gateway_error( |
| 127 |
|
__( 'Stripe Error', 'give' ), |
| 128 |
|
sprintf( |
| 129 |
|
/* translators: %s Exception Message Body */ |
| 130 |
|
__( 'Unable to set Stripe API Version. Details: %s', 'give' ), |
| 131 |
|
$e->getMessage() |
| 132 |
|
) |
| 133 |
|
); |
| 134 |
|
give_set_error( 'stripe_error', __( 'An error occurred while processing the donation. Please try again.', 'give' ) ); |
| 135 |
|
|
| 136 |
|
// Send donor back to checkout page on error. |
| 137 |
|
$this->send_back_to_checkout(); |
| 138 |
|
} |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
/** |
| 142 |
|
* Send back to checkout based on the gateway id. |
|
@@ 206-234 (lines=29) @@
|
| 203 |
|
* |
| 204 |
|
* @return \Stripe\Source |
| 205 |
|
*/ |
| 206 |
|
public function get_source_details( $id ) { |
| 207 |
|
|
| 208 |
|
// Set Application Info. |
| 209 |
|
give_stripe_set_app_info(); |
| 210 |
|
|
| 211 |
|
try { |
| 212 |
|
|
| 213 |
|
// Retrieve Source Object. |
| 214 |
|
return \Stripe\Source::retrieve( $id, give_stripe_get_connected_account_options() ); |
| 215 |
|
|
| 216 |
|
} catch ( \Stripe\Error\Base $e ) { |
| 217 |
|
$this->log_error( $e ); |
| 218 |
|
} catch ( Exception $e ) { |
| 219 |
|
|
| 220 |
|
// Something went wrong outside of Stripe. |
| 221 |
|
give_record_gateway_error( |
| 222 |
|
__( 'Stripe Source Error', 'give' ), |
| 223 |
|
sprintf( |
| 224 |
|
/* translators: %s Exception Message Body */ |
| 225 |
|
__( 'Unable to retrieve source. Details: %s', 'give' ), |
| 226 |
|
$e->getMessage() |
| 227 |
|
) |
| 228 |
|
); |
| 229 |
|
give_set_error( 'stripe_error', __( 'An error occurred while processing the donation. Please try again.', 'give' ) ); |
| 230 |
|
|
| 231 |
|
// Send donor back to checkout page on error. |
| 232 |
|
$this->send_back_to_checkout(); |
| 233 |
|
} |
| 234 |
|
} |
| 235 |
|
|
| 236 |
|
/** |
| 237 |
|
* This function will prepare source based on the parameters provided. |
|
@@ 246-274 (lines=29) @@
|
| 243 |
|
* |
| 244 |
|
* @return \Stripe\Source |
| 245 |
|
*/ |
| 246 |
|
public function prepare_source( $args ) { |
| 247 |
|
|
| 248 |
|
// Set Application Info. |
| 249 |
|
give_stripe_set_app_info(); |
| 250 |
|
|
| 251 |
|
try { |
| 252 |
|
|
| 253 |
|
// Create Source Object. |
| 254 |
|
return \Stripe\Source::create( $args, give_stripe_get_connected_account_options() ); |
| 255 |
|
|
| 256 |
|
} catch ( \Stripe\Error\Base $e ) { |
| 257 |
|
$this->log_error( $e ); |
| 258 |
|
} catch ( Exception $e ) { |
| 259 |
|
|
| 260 |
|
// Something went wrong outside of Stripe. |
| 261 |
|
give_record_gateway_error( |
| 262 |
|
__( 'Stripe Error', 'give' ), |
| 263 |
|
sprintf( |
| 264 |
|
/* translators: %s Exception Message Body */ |
| 265 |
|
__( 'Unable to create source. Details: %s', 'give' ), |
| 266 |
|
$e->getMessage() |
| 267 |
|
) |
| 268 |
|
); |
| 269 |
|
give_set_error( 'stripe_error', __( 'An error occurred while processing the donation. Please try again.', 'give' ) ); |
| 270 |
|
|
| 271 |
|
// Send donor back to checkout page on error. |
| 272 |
|
$this->send_back_to_checkout(); |
| 273 |
|
} |
| 274 |
|
} |
| 275 |
|
|
| 276 |
|
/** |
| 277 |
|
* Get Customer's card. |