Php 与西方商业分道扬镳
我正在尝试使用splitwise创建一个“支付网关”来创建费用,我使用它来创建费用,我已经创建了下面的代码段来以splitwise生成费用,但是每次我单击place order时,我收到的消息是“请再试一次” 我是api方面的新手,所以我不知道是否有错误,任何帮助都会非常好,谢谢Php 与西方商业分道扬镳,php,woocommerce,Php,Woocommerce,我正在尝试使用splitwise创建一个“支付网关”来创建费用,我使用它来创建费用,我已经创建了下面的代码段来以splitwise生成费用,但是每次我单击place order时,我收到的消息是“请再试一次” 我是api方面的新手,所以我不知道是否有错误,任何帮助都会非常好,谢谢 public function process_payment( $order_id ) { global $woocommerce; // we need it
public function process_payment( $order_id ) {
global $woocommerce;
// we need it to get any order detailes
$order = wc_get_order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
$product_name = $item->get_name();
$product_id = $item->get_product_id();
$product_variation_id = $item->get_variation_id();
}
/*
* Array with parameters for API interaction
*/
$args = array(
'cost' => $order->get_total(),
'group_id' => 0,
'description' => $product_name,
'details' => 'string',
'repeat_interval'=> 'never',
'split_equally'=> true
);
/*
* Your API interaction could be built with wp_remote_post()
*/
$response = wp_remote_post( 'https://secure.splitwise.com/api/v3.0/create_expense', $args );
if( !is_wp_error( $response ) ) {
$body = json_decode( $response['body'], true );
// it could be different depending on your payment processor
if ( $body['response']['responseCode'] == 'APPROVED' ) {
// we received the payment
$order->payment_complete();
$order->reduce_order_stock();
// some notes to customer (replace true with false to make it private)
$order->add_order_note( 'Hey, your order is paid! Thank you!', true );
// Empty cart
$woocommerce->cart->empty_cart();
// Redirect to the thank you page
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order )
);
} else {
wc_add_notice( 'Please try again.', 'error' );
return;
}
} else {
wc_add_notice( 'Connection error.', 'error' );
return;
}
}```