Error submitting an encrypted subscription button.

hippocalypse
Contributor
Contributor

Hey everyone,

 

I've got two buttons on my checkout that utilize vue to request an encryption, fill the form, and then pass to paypal.

 

One of the buttons is a standard transaction _xclick (Checkout.vue, works) and the other is a subscription _xclick-subscriptions (Autoship.vue fails).

 

Is there something I am missing because my first button successfully passes to paypal, but my subscription button fails due to NOBUSINESS.

I can confirm my vue data has filled before the form is submitted, which is why I am stumped.

 

Here's my relevant code:

 

PaypalController.php {


public static final function getCheckoutHash(Order $order) {
return PaypalController::encrypt([
'cert_id' => env('PAYPAL_CERT_ID'), //per paypal
'cmd' => '_xclick',
'business' => '<removed>',
'lc' => 'US',
'amount' => $order->grand_total,
'item_name' => $order->summary,
'item_number' => $order->hash,
'button_subtype' => 'services',
'no_note' => 0,
'no_shipping' => 0,
'notify_url' => 'https://mysite.com/paypal/ipn',
'return' => 'https://mysite.com/receipt',
'cancel' => 'https://mysite.com/cart',
'currency_code' => 'USD',
'bn' => 'PP-BuyNowBF:btn_paynowCC_LG.gif:NonHosted'
]);
}

/**
* Setup autoshipping between 1 and 90 day intervals for the specified Order.
*
* @Param Order $order
* @Param type $days
* @RETURN string encryped
*/
public static final function getAutoshipHash(Order $order, $days = 30) {
$days = $days > 90 ? 90 : ($days < 1 ? 1 : $days);

return PaypalController::encrypt([
'cert_id' => env('PAYPAL_CERT_ID'), //per paypal
'cmd' => '_xclick-subscriptions',
'business' => '<removed>',
'currency_code' => 'USD',
'a3' => $order->grand_total,
'p3' => $days,
't3' => "D", //days
'item_name' => $order->summary,
'item_number' => "Autoship#".$order->hash,
'src' => 1, //recurring
'return' => 'https://mysite.com/receipt',
'cancel_return' => 'https://mysite.com/cart'
]);
}

 

}

 

Autoship.vue {

 

<template>
<div>
<form id="autoship-form" class='pp-button' action="https://www.paypal.com/cgi-bin/webscr" @Submit.stop.prevent="onSubmit" method="post" target="_top">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="encrypted" v-model="hash">
<span>Autoship every <input type="number" v-model.number="days"> days with</span>
<input class="right" type='image' name='submit' src='https://www.paypalobjects.com/webstatic/en_US/i/buttons/PP_logo_h_100x26.png'>
</form>
</div>
</template>

<script>
export default {
props: {
order: {
type: String,
required: true
}
},

data() {
return {
hash: null,
days: 30
};
},

methods: {
onSubmit() {
this.$emit('loading');
axios.get(`/orders/${this.order}/autoship/${this.days}`)
.then(response => {
if(!response.data) {
error("Malformed parameter: days");
this.$emit('loaded');
return;
}

this.hash = response.data;

let that = this;
this.$nextTick( function () {
if(that.hash) document.getElementById('autoship-form').submit();
else that.$emit('loaded');
});

//loading continues until we are offsite

}).catch(err => {
error(err.message);
this.$emit('loaded');
});
}
},

watch: {
days: function(val) {
if(val < 1) { this.days = 1; }

if(val > 90) { this.days = 90; }
}
}
}
</script>

 

}

 

 

Lastly, Checkout.vue {

 

<template>
<div>
<form id="checkout-form" class='pp-button' action="https://www.paypal.com/cgi-bin/webscr" @Submit.stop.prevent="onSubmit" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" v-model="hash">
<span>Checkout with</span>
<input class="right" type='image' name='submit' src='https://www.paypalobjects.com/webstatic/en_US/i/buttons/PP_logo_h_100x26.png'>
</form>
</div>
</template>

<script>
export default {
props: {
order: {
type: String,
required: true
}
},

data() {
return {
hash: null,
};
},

methods: {
onSubmit() {
this.$emit('loading');
axios.get(`/orders/${this.order}/checkout`)
.then(response => {
this.hash = response.data;

let that = this;
this.$nextTick( function () {
if(that.hash) document.getElementById('checkout-form').submit();
else that.$emit('loaded');
});

//loading continues until we are offsite
}).catch(err => {
error(err.message);
this.$emit('loaded');
});
}
}
}
</script>

 

}

 

PS- sorry, I couldnt figure out how to format the codeblock on this forum.

 

Thanks for any tips!

 

 

 

 

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.